【发布时间】:2013-07-29 09:46:45
【问题描述】:
tableview 的每个单元格中都有一个按钮。基本上我正在保存单元格的 indexPath in the button's tag in thecellForRowAtIndexPath` 方法,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UIButton *expandPhoto = (UIButton *)[cell viewWithTag:101];
expandPhoto.tag = indexPath.row;
[expandPhoto addTarget:self action:@selector(expand:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
问题是,当我向下滚动按钮时,indexPath 会重置。
我在互联网上搜索了很多,但我被这个问题困扰了好几天。
【问题讨论】:
-
你怎么知道 indexpath 改变了?添加代码。使用故事板?
-
是的,我正在使用情节提要,并且我知道 indexPath 不是 NSLogs 应该有的(它应该显示 6 时显示 indexPath 0,应该显示 7 时显示 1,等等. 另外,我正在使用原型单元格。
标签: iphone ios button tags tableview