2011-09-19 66 views

回答

0

很简单的实际。在按钮的处理程序方法中,创建表视图控制器并以模态方式显示它或将其推入导航堆栈。

[myButton addTarget:self action:@selector(displayTableView:) forControlEvents:UIControlEventTouchUpInside]; 

-(void)displayTableView:(id)sender 
{ 
     MyTableViewController* myTVC = [[MyTableViewController alloc] initWithNibName:@"myTVC" bundle:nil]; 
    [self.navigationController presentModalViewController:myTVC animated:YES]; 
    //[self.navigationController pushViewController:myTVC animated:YES]; //2nd option 
    [myTVC release]; 
} 
+0

谢谢你的建议,但我有两个问题。 (1)您的代码的第一行是将事件处理程序添加到按钮,似乎它可以通过接口生成器完成? (2)什么时候应该使用presentModalViewController和pushViewController?谢谢 –

+0

1)是的,它可以通过IB完成。使用按钮将按钮显示为IBOutlet并在IB中的发送事件中连接'向上触摸'。 2)取决于你的应用程序的UI设计。我更愿意推iPad上的iPhone和模式。 – Akshay

+0

感谢您的信息 –