UITable单元格选择中的问题

时间:2009-09-11 06:09:56

标签: iphone uinavigationcontroller

海, 我已经在UITableview中编码如下方法。但是当我触摸单元格或行时,它不会 转到下一页(导航没有工作)。我要在其他文件中声明导航控制器。但我已经在applicationdidfinishmethod编码应用程序委托通过dynamic.how标签栏我可以链接导航吗? 代码:   的的UITableView; (适用的 TableViewController)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        SubController *nextController = [[SubController alloc] init];
    [self.navigationController pushViewController:nextController animated:YES];
    [nextController release];
}

appdelegation:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    



         tabBarController = [[UITabBarController alloc] init];
    tabBarController.navigationItem.title = @" News";
    TableViewController *rtbfViewController = [[TableViewController alloc] 
         init];

    rtbfViewController.tabBarItem.title = @"News";
    InfoViewController *infoViewController = [[InfoViewController alloc] 
              initWithStyle:UITableViewStyleGrouped];
    infoViewController.tabBarItem.title = @"Info";
    tabBarController.viewControllers = [NSArray 
             arrayWithObjects:rtbfViewController,infoViewController,nil];
    tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];


        [window addSubview:tabBarController.view];
         [window makeKeyAndVisible];
}

1 个答案:

答案 0 :(得分:1)

问题是,您没有UINavigationController,因此self.navigationController中的TableViewController为零(因此会忽略发送到此属性的消息)。您应该在app delegate中修改代码,如下所示:

// [...] create tab bar view controller...

// create navigation controller with TableViewController instance as root view controller
TableViewController *rtbfViewController = [[TableViewController alloc] init];
rtbfViewController.tabBarItem.title = @"News";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rtbfViewController];

// [...] create other view controllers

// NOTE: add the navigation controller to the tab bar controller, rather than the TableViewController
tabBarController.viewControllers = [NSArray arrayWithObjects:navController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];

不要忘记之后发布你的视图控制器:

[rtbfViewController release];
[navController release];
[infoViewController release];