【问题标题】:uitabbarcontroller + uitableviewcontroller + uiviewcontrolleruitabbar 控制器 + uitableview 控制器 + uiview 控制器
【发布时间】:2010-02-09 15:29:18
【问题描述】:

我正在使用从 URL 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];
}

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

【问题讨论】:

    标签: iphone uitabbarcontroller uitableview


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      复制所有这些代码并将其粘贴到现有位置即可。

      - (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];
      }
      

      【讨论】:

        【解决方案3】:
        -(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];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-11-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-05
          相关资源
          最近更新 更多