ios - MGSwipeTableCellDelegate : Not Working
<p><p>这快把我逼疯了。</p>
<p>我已经实现了MGSwipeTableCell,当它分别向左右滑动时,它在左侧显示三个按钮,在右侧显示一个按钮。
<a href="https://github.com/MortimerGoro/MGSwipeTableCell" rel="noreferrer noopener nofollow">https://github.com/MortimerGoro/MGSwipeTableCell</a> </p>
<p>但是,在滑动后按下这些按钮时,我无法触发委托(delegate)方法。这是我的代码的摘录。</p>
<p>detailviewcontroller.h</p>
<pre><code>@interface DetailViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, MGSwipeTableCellDelegate>
</code></pre>
<p>detailviewcontroller.m</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DataStruct *showCredit;
static NSString *CellIdentifier = @"Credit_Cell";
MGSwipeTableCell *cell = ;
if (cell == nil) {
//cell = [ initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Credit_Cell"];
cell = [ initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Credit_Cell"];
}
cell.leftButtons = ;
cell.leftSwipeSettings.transition = MGSwipeTransition3D;
cell.rightButtons = ;
cell.rightSwipeSettings.transition = MGSwipeTransition3D;
cell.delegate = self;
return cell;
}
-(NSArray*) swipeTableCell:(MGSwipeTableCell*) cell swipeButtonsForDirection:(MGSwipeDirection)direction
swipeSettings:(MGSwipeSettings*) swipeSettings expansionSettings:(MGSwipeExpansionSettings*) expansionSettings
{
NSIndexPath *myPath = ;
NSLog(@"Pressed Credit last = %d", myPath.row);
...
}
</code></pre>
<p>我的目标:获取滑动后按下按钮的 indexpath.row。有人能把我引向正确的方向吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用 <code>tappedButtonAtIndex</code> 委托(delegate)方法获取单击按钮所在单元格的 <code>indexpath</code>。 </p>
<pre><code>-(BOOL) swipeTableCell:(MGSwipeTableCell*) celll tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion{
NSIndexPath *indexPath = ;
NSInteger rowOfTheCell = ;
NSInteger sectionOfTheCell = ;
NSLog(@"rowofthecell %ld", rowOfTheCell);
NSLog(@"sectionOfTheCell %ld", sectionOfTheCell);
return NO; // If you don't want to hide the cell.
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - MGSwipeTableCellDelegate : Not Working,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/30397539/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/30397539/
</a>
</p>
页:
[1]