【发布时间】:2013-07-16 00:37:58
【问题描述】:
我有一个基于 UITabBarController 模板的应用程序,其中第一个选项卡是 UITableViewController,单元格中有自定义按钮。我需要一个单元格中的一个按钮来调用父 UITabBarController 中的特定选项卡。我在 didSelectRowAtIndexPath 中使用此代码:
case 5:
NSLog(@"Search");
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Get UITabBar instance and send it message
UITabBarController *tabBar = (UITabBarController*)[self parentViewController];
[tabBar setSelectedIndex:1];
break;
当我点击此行时,应用程序在控制台中没有任何日志的情况下崩溃。我在 UITableViewController 中调用它,它是 UITabBarController 中的第一个选项卡。
PS 我还想避免在用户点击时出现在此单元格上的蓝色选择。所以我添加了这段代码:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 1:
return nil;
break;
}
}
但是当我点击它时它仍然选择蓝色。它们可能是相关的问题吗?
【问题讨论】:
-
你的意思是像this?
-
您可以通过为单元格设置选择样式
UITableViewCellSelectionStyleNone来避免蓝色选择。case 5在didSelectRowAtIndexPath中指的是什么?