2009-09-11 9 views
0

hai, J'ai codé en UITableview dans la méthode comme suit. Mais quand je touche la cellule ou la ligne, il ne va pas à la page suivante (la navigation n'a pas fonctionné). Je dois déclarer conroller de navigation dans d'autres fichiers. mais j'ai codé le délégué de l'application dans applicationdidfinishmethod pour la barre d'onglets via dynamic.how puis-je lier la navigation? le code: UITableview; (TableViewController)problème dans la sélection de cellule UITable

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

Répondre

1

Le problème est que vous ne disposez pas d'un UINavigationController, donc self.navigationController dans votre TableViewController est nulle (et donc les messages envoyés à cette propriété est ignorée). Vous devez modifier votre code dans le délégué de l'application comme suit:

// [...] 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]; 

Et ne pas oublier de libérer votre vue des contrôleurs après:

[rtbfViewController release]; 
[navController release]; 
[infoViewController release]; 
Questions connexes