【发布时间】:2023-04-09 16:41:01
【问题描述】:
我有一个 XCode iPHone 项目设置,其中包含以下内容:
我的 App Delegate 创建了一个动态 tabBarController 并向其中添加了两个视图控制器。其中之一包含一个 TableView。
从该 TableView 中,我希望用户能够单击每个项目上的蓝色箭头按钮并获取有关它的更多详细信息。这是一个非常标准的事情......这是我必须这样做的代码:
-(void)tableView: (UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *) indexPath {
[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if (self.switchView == nil) {
SwitchViewController *viewController = [[SwitchViewController alloc] initWithNibName:@"SwitchViewController" bundle:[NSBundle mainBundle]];
self.switchView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.switchView animated:YES];
self.switchView.title = @"Test Title";
}
现在,我的 SwitchViewController 只是一个带有按钮的空白视图。 当用户单击蓝色按钮时,什么也没有发生。我可以在其中设置一个断点并查看所有正在执行的代码,但 iPhone 屏幕根本没有改变。
有什么建议吗?我确信这是一些基本的东西,因为我对 iOS 开发还很陌生。
提前致谢!
R
【问题讨论】:
-
你检查过 navigationController 不是 nil 吗?你没有在你的层次结构中提到任何 UINavigationControllers...
-
还要检查
viewController以确保它已从 NIB 正确实例化。 -
@Vladimir - 我没有专门设置“navigationController”,我只是假设我当前的视图是导航控制器。这段代码所在的tableview页面继承自UITableViewController。知道有一篇文章提供了有关实际 navigationController 设置的更多详细信息吗?
-
@kubi - 我有什么迹象表明它没有正确设置?当我在那个点中断时,viewController 对象有一个值,我可以展开它并查看我的按钮等。
-
@Chu,首先从基于导航的应用程序模板创建一个项目以查看一般结构。
标签: objective-c cocoa-touch uikit ios