【发布时间】:2015-01-06 06:22:30
【问题描述】:
我有一个自定义的 tableView 设置,它不会使单元格出队。我没有在情节提要中使用静态单元格,因为我使用的是包含 tableView 的 UIViewController。不管设置如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
// Array > Dictionary > cell.textLabel.text info here
switch (indexPath.section) {
case 0:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
switch (indexPath.row) {
case 4:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDetailButton;
//etc etc
单元格的设置与上述代码显示的相同。
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *pubdisclaimer = [NSIndexPath indexPathForRow:2 inSection:2];
NSIndexPath *maintenanceInfo = [NSIndexPath indexPathForRow:4 inSection:0];
if (indexPath == pubdisclaimer) {
NSLog(@"Disclaimer Tapped");
//Show UIAlertController
} else if (indexPath == maintenanceInfo) {
NSLog(@"Maintenance tapped");
//Show Different UIAlertController
} else {
//
}
}
在模拟器中检测到附件ButtonTapped(并且相应地填充不同的 UIAlertController)但是,当在与模拟器相同的部署目标的设备上运行时,除了按钮突出显示之外什么都没有发生。这适用于一个 indexPath,但是当我包含 else if 语句时,它不会在设备上调用。
仅供参考,所有 tableView 委托和数据源都已正确设置为文件所有者。就像我说的,在我添加第二个 NSIndexPath 之前一切正常,这让我相信这就是问题所在。但如果是这样的话,为什么它在模拟器中可以完美运行,甚至区分两个不同的按钮索引?我想我在这里遗漏了一些简单的东西。如何解决问题?
编辑记录索引路径:
模拟器返回
2015-01-05 21:42:54.666 [38440:9202972] didSelectRowAtIndexPath section: 0, row: 4
2015-01-05 21:42:57.993 [38440:9202972] accessoryButtonTapped section: 0, row: 4
2015-01-05 21:43:04.765 [38440:9202972] didSelectRowAtIndexPath section: 2, row: 2
2015-01-05 21:43:08.185 [38440:9202972] accessoryButtonTapped section: 2, row: 2
设备退货
2015-01-05 21:45:17.564 [4072:1128326] didSelectRowAtIndexPath section: 0, row: 4
2015-01-05 21:45:19.763 [4072:1128326] Nothing tapped : else
2015-01-05 21:45:28.613 [4072:1128326] didSelectRowAtIndexPath section: 2, row: 2
2015-01-05 21:45:29.313 [4072:1128326] Nothing tapped : else
【问题讨论】:
-
在
else块中添加一个警报,并检查您的情况是否会出现。 -
@Mrunal 测试,结果如您所料。两个附件按钮 NSLog 到 else 语句。这证实了两个 indexPaths 都是正确的。但是,仍然很困惑为什么它可以在模拟器上运行。你有什么建议
-
NSLog(@"section: %d, row: %d", indexPath.section, indexPath.row);在模拟器和设备上。然后比较为什么它对两者都不同。在这里你需要深入研究代码。
-
@Mrunal 感谢更新问题
标签: ios uitableview