uitabbarcontroller + uitableviewcontroller + uiviewcontroller

时间:2010-02-09 15:29:19

标签: iphone uitabbarcontroller uitableview

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

- (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 setText=@"Testing label"];
    [self.navigationController pushViewController:dv animated:YES];
    [dv release];
}

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

3 个答案:

答案 0 :(得分:1)

这会编译吗? [dv.label setText=@"Testing label"];不是Objective-C。它应该是:

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

答案 1 :(得分:0)

-(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];  
    chats.title=@"Chats";

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

    contacts.title=@"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];

答案 2 :(得分:0)

复制所有这些代码并将其粘贴到现有代码上。

- (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 setText=@"Testing label"];
    [dv release];
}