从 UITableViewCell 访问新的 UIViewController
我有一个选项卡栏应用程序,其中有 6 个选项卡栏项目,每个选项卡栏项目都打开一个 UITableView。我试图使每个表能够在选择表上一行中的项目时打开详细视图控制器。
例如,对于第一个 ViewController ( ViewController1.m
),我创建了
DetailView1.xib
DetailViewController1.h
DetailViewController1.m
为了获取 ViewController1.m 的 TableView 中的每一行,我知道我必须 使用此方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
这是我的该方法的代码,它不会产生任何错误或警告,但选择 TableViewCell 时不会发生任何事情:
DetailViewController1 *dvController = [[DetailViewController1 alloc] initWithNibName:@"DetailView1" bundle:[NSBundle mainBundle]];
[navController pushViewController:dvController animated:YES];
[dvController release];
这是否应该加载 DetailView1.xib?我用选项卡栏应用程序模板创建了这个...我相信默认情况下它没有导航控制器。是否有可能某些东西没有在 Interface Builder 中正确连接?
I have a Tab Bar application with 6 Tab Bar items that each open a UITableView. I am trying to enable each table with the ability to open a Detail View Controller when an item in a row on the table is selected.
For example, for the first ViewController ( ViewController1.m
), I created
DetailView1.xib
DetailViewController1.h
DetailViewController1.m
In order to get each row in ViewController1.m 's TableView, I understand I must
use this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
This is my code for that method, which does not produce any errors or warnings, but nothing sees to happen when the TableViewCell is selected:
DetailViewController1 *dvController = [[DetailViewController1 alloc] initWithNibName:@"DetailView1" bundle:[NSBundle mainBundle]];
[navController pushViewController:dvController animated:YES];
[dvController release];
Should this not load DetailView1.xib? I created this with the Tab Bar Application Template...which has no NavigationController in it by default I believe. Is it possible something is not hooked up right in Interface Builder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要配置每个选项卡以包含
UINavigationController
的实例,并在其中嵌套一个视图控制器。然后在tableView:didSelectRowAtIndexPath:
中,您需要将示例中的第二行代码更改为:You'd need to configure each tab to contain an instance of
UINavigationController
with one of your view controllers nested inside of it. Then intableView:didSelectRowAtIndexPath:
, you'd want to change the second line of code in your example to this: