我有以下代码:
- (IBAction)showDirectMessage:(id)sender
{
DetailMessageViewController * dmvc = [[DetailMessageViewController alloc] init];
dmvc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:dmvc animated:YES];
}
我在这里要做的是呈现一个顶部有一个NavigationBar的视图,一个UITableView作为里面的视图。但是截至目前它只显示了UITableView。我对需要改变的事感到困惑。在我的DetailMessageViewController IB中,我拖入UINavigationController并将UITableView作为视图放入其中。但是,我将UINavigationController连接到UITableView视图..我认为这是错误的。我不知道我该怎么做。有人可以指导我吗?
答案 0 :(得分:3)
您应该使用ViewController提供新的NavigationController。
- (IBAction)showDirectMessage:(id)sender
{
DetailMessageViewController * dmvc = [[DetailMessageViewController alloc] init];
UINavigationController *naviContoroller = [[UINavigationController alloc] initWithRootViewController:dmvc];
naviContoroller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:naviContoroller animated:YES];
[naviContoroller release];
[dmvc release];
}
答案 1 :(得分:0)
DetailMessageViewController *dmvc=[[[DetailMessageViewController alloc]initWithNibName:@"DetailMessageViewController" bundle:nil]autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:dmvc]autorelease];
[navController setModalTransitionStyle:UIModalPresentationFormSheet];
[[self navigationController] presentModalViewController:navController animated:YES];