2010-02-09 76 views
0

我使用從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]; 
} 

但它沒有顯示任何文字。可以通過指出我的代碼中有什麼錯誤來幫助我嗎?

回答

1

這是否編譯? [dv.label [email protected]"Testing label"];不是Objective-C。它應該閱讀:

[dv.label setText:@"Testing label"]; 
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]; 
    [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]; 
0

複製這些代碼,並在現有的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]; 
} 
相關問題