UIBarButtonItem未显示

时间:2010-11-25 05:28:24

标签: iphone uibutton uibarbuttonitem uibarbuttonitemstyle

我有一个名为“takeAction”的模态视图控制器。我正在尝试在向用户呈现模态视图控制器时在takeAction中加载UIBarButtonItem。因此,UIBarButtonItem与模态视图控制器的内容是异步的。

但按钮根本不存在。我该如何解决这个问题?

代码:

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *navController = [delegate navController];
[navController presentModalViewController: takeAction animated:YES];

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonItemStyleDone
target:self action:@selector(done)];

takeAction.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];

1 个答案:

答案 0 :(得分:0)

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:@selector(done)];

takeAction.navigationItem.rightBarButtonItem = doneButton ;
[doneButton release];

将上面的行放在这一行:

UINavigationController *navController = [delegate navController]; 
[navController presentModalViewController: takeAction animated:YES];