使用模态View iphone将栏添加到导航栏

时间:2010-07-14 17:30:20

标签: iphone uibarbuttonitem modalviewcontroller

在我的应用程序中,我正在呈现一个modalViewController,其顶部有一个导航栏,但我无法向navigatiobar添加barbuttons。我正在使用以下代码:

编辑:

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];

提前完成。

1 个答案:

答案 0 :(得分:1)

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];