我有一个UITableViewController
这样的。UIBarButtonItem
每行的附件视图中都有一个分组表视图。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIToolbar *toolBar = [[TransparentToolbar alloc] init];
UIBarButtonItem *loginButton = [[UIBarButtonItem alloc] initWithTitle:@"Check"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(login:)];
toolBar.frame = CGRectMake(0, 0, 100, 103);
toolBar.items = @[loginButton];
cell.accessoryView = toolBar;
return cell;
}
现在我试图UITableViewCell
在点击相应的UIBarButtonItem
. (来源)
- (void)login:(UIBarButtonItem *)button
{
UIBarButtonItem *barButton = button;
UIView *view = [barButton valueForKey:@"view"];
UITableViewCell *cell = (UITableViewCell *)view.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSLog(@"secton: %d", indexPath.section);
}
但无论我点击哪个栏按钮,它都只返回 0。任何人都可以告诉我它有什么问题以及如何纠正这个问题?我真的很感激。
谢谢你。