對於某些人來說,這可能看起來像一個愚蠢的問題,但在iPhone應用程序中處理不同類型的控制器對我來說仍然有點模糊。這裏的設置:將導航控制器添加到選項卡欄應用程序(以編程方式)
我有一個選項卡欄應用程序與四個選項卡。每個選項卡都將控制權交給其各自的ViewController,其中一些選項用.XIB文件初始化,一些則完全以編程方式完成。其中一個程序化的是DirectionsViewController
,其本質上是UITableViewController
。從表格中選擇一個單元格需要(模態地)呈現DetailedDirectionsViewController
,它需要對呈現視圖控制器進行某種反向引用。我認爲最簡單的方法是將導航控制器添加到Directions
和DetailedDirections
VC - 除非我不知道如何在沒有.XIB文件的情況下執行此操作。
而且,我用手控制權交給DetailedDirections
的方法是通過改變Directions
方式如下:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailedDirectionsViewController *vc = [[DetailedDirectionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.tabBarController presentModalViewController:vc animated:YES];
}
我似乎記得我的教授說,presentModalViewController
是一種古老的方法之一,並有更好的替代品...我現在不記得他們。
看看http://bit.ly/H4kHEZ,可以看看該文檔中的示例代碼。 – 2012-03-30 18:39:51