使用iPhone中的modalView向导航栏添加按钮

使用iPhone中的modalView向导航栏添加按钮,iphone,uibarbuttonitem,modalviewcontroller,Iphone,Uibarbuttonitem,Modalviewcontroller,在我的应用程序中,我展示了一个顶部带有导航栏的modalViewController,但我无法向导航栏添加按钮。我正在使用以下代码: displayController = [[UIViewController alloc]initWithNibName:nil bundle:nil]; UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:displayContr

在我的应用程序中,我展示了一个顶部带有导航栏的modalViewController,但我无法向导航栏添加按钮。我正在使用以下代码:

displayController = [[UIViewController alloc]initWithNibName:nil bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:displayController];

[displayController setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                            initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                            target:self
                            action:@selector(displayViewForPosts)];

displayController.navigationItem.rightBarButtonItem = submit;
[submit release];

UIBarButtonItem *newsfeed = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
displayController.navigationItem.leftBarButtonItem = newsfeed;
[newsfeed release];

[self presentModalViewController:cntrol animated:YES];
[cntrol release];
[displayController release];

Thanx Aaron感谢您的回复,但它仍然不起作用。。我已经用更新的代码编辑了我的问题。。你能告诉我哪里出了问题吗?你有什么问题?模态视图还没有显示吗?没有,modalview也显示得更早。。我不知道是怎么回事,但突然按钮出现了。。谢谢你的帮助好的,有个问题。。这些按钮的显示方式与普通工具栏按钮类似,没有导航按钮那样的方向。我希望这些类型的方向按钮,这将更好地为用户。我正在看这个和越来越多的我的东西,你不想使用presentModalViewController,我想你只是想把新的视图推到现有的navigationController堆栈。您选择presentModalViewController有什么原因吗?Thanx Aaron感谢您的回复,但它仍然不起作用。。我已经用更新的代码编辑了我的问题。。你能告诉我哪里出了问题吗?你有什么问题?模态视图还没有显示吗?没有,modalview也显示得更早。。我不知道是怎么回事,但突然按钮出现了。。谢谢你的帮助好的,有个问题。。这些按钮的显示方式与普通工具栏按钮类似,没有导航按钮那样的方向。我希望这些类型的方向按钮,这将更好地为用户。我正在看这个和越来越多的我的东西,你不想使用presentModalViewController,我想你只是想把新的视图推到现有的navigationController堆栈。您选择presentModalViewController有什么原因吗?
UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:detailViewController];

[detailViewController setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
detailViewController.navigationItem.rightBarButtonItem = submit;
[submit release];


[self.navigationController presentModalViewController:cntrol animated:YES];
[cntrol release];