uitabbarcontroller + uitableviewcontroller + uiviewcontroller

问题描述:

我使用从URL http://www.iphonemusings.com/2009/01/iphone-programming-tutorial-creating.html中提取的代码显示带有选项卡栏的初始屏幕,并在两个选项卡中都显示了表格视图。 在对表格视图委托进行必要的更改后,它在单元格中显示文本。 现在我想显示点击表格视图的视图。我正在使用以下代码。uitabbarcontroller + uitableviewcontroller + uiviewcontroller

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    Latest* evnt = (Latest*)[latestArray objectAtIndex:indexPath.row]; 
    NSString* url = [evnt URLLink]; 
    DetailedView* dv = [[DetailedView alloc] init]; 
     [dv.label [email protected]"Testing label"]; 
    [self.navigationController pushViewController:dv animated:YES]; 
    [dv release]; 
} 

但它没有显示任何文字。可以通过指出我的代码中有什么错误来帮助我吗?

这是否编译? [dv.label [email protected]"Testing label"];不是Objective-C。它应该阅读:

[dv.label setText:@"Testing label"]; 

-(void)viewDidLoad 
{ 
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    contentView.backgroundColor = [UIColor whiteColor]; 
    self.view = contentView; 

    ChatsViewController *chats=[[ChatsViewController alloc] initWithNibName:@"ChatsViewController" bundle:nil]; 

    UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:chats]; 
    [email protected]"Chats"; 

    ContactsViewController *contacts=[[ContactsViewController alloc] initWithNibName:@"ContactsViewController" bundle:nil]; 
    UINavigationController *contacts1 = [[UINavigationController alloc] initWithRootViewController:contacts]; 

    [email protected]"Contacts"; 

    UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460); 

    [tabBarController setViewControllers:[NSArray arrayWithObjects:searchNav,contacts1,accounts1,settings1, nil]]; 

    [self.view addSubview:tabBarController.view]; 
} 

试试这个代码。代码将显示UITabBarController两个选项卡。您可以在两个选项卡中创建表格。在didSelectRowAtIndexPath中,使用navigationController编写推送视图的代码。当你在表格中选择一行时,它将显示一个新的视图。

SignInViewController *signIn=[[SignInViewController alloc] initWithNibName:@"SignInViewController" bundle:nil]; 

[self.navigationController pushViewController:signIn animated:YES]; 

复制这些代码,并在现有的IT将工作粘贴。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    Latest* evnt = (Latest*)[latestArray objectAtIndex:indexPath.row]; 
    NSString* url = [evnt URLLink]; 
    DetailedView* dv = [[DetailedView alloc] init]; 

    [self.navigationController pushViewController:dv animated:YES]; 
[dv.label [email protected]"Testing label"]; 
    [dv release]; 
}