2012-03-14 22 views

回答

6

重写这个UItableViewDelegate的委托方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//Value Selected by user 
     NSString *selectedValue = [displayValues objectAtIndex:indexPath.row]; 
//Initialize new viewController 
     NewViewController *viewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil]; 
//Pass selected value to a property declared in NewViewController 
     viewController.valueToPrint = selectedValue; 
//Push new view to navigationController stack 
     [self.navigationController pushViewController:viewController animated:YES]; 
} 

看到这个链接,了解更多信息
1)Table view tutorial
2)StackOverflow similar question

2

您可以使用UINavigationController并在didSelectRowAtIndePath:方法中调用pushViewController:

要显示信息,我会创建一个新的UIViewController,并创建一些可以设置用于显示信息的属性。

0

您必须实现方法的一码“(无效)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath'。当您选择表格中的单元格时,将调用此方法。这就是为什么你必须实现你想要的。

我希望以下代码对您有所帮助。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 



        if (!yourObject) { 
        yourObject = [[yourViewController alloc] initWithNibName:@"yourViewController" bundle:nil]; 

       } 

       UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]; 
       self.navigationItem.backBarButtonItem = backBarButtonItem; 
       [backBarButtonItem release]; 
       [self.navigationController pushViewController:yourObject animated:YES]; 

    } 
0

尝试这种在didSelectRowAtIndexPath方法,你可以创建该类的对象,你可以 用户:NavigationController或者presentModleViewController去另一个视图。

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

[self presentModalViewController:yourClassobject animated:YES];