所以我有一個問題,我的rightbarbuttonitem消失。我有兩種方法加載這個視圖,第一次啓動它後,用戶輸入他們的名字(從初始視圖)加載它。第二次(在應用程序退出後),它會檢查我的存儲數據庫中是否存在該名稱,如果它存在,則立即加載視圖。第二次是按鈕不顯示的地方。iPhone SDK - > RightBarButtonItem通過AppDelegate加載視圖時消失
按鈕在viewDidLoad中設置我的觀點的最初這裏(和仍然設置在這裏第負載):
if (self.navigationItem.rightBarButtonItem == nil){
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(buttonPressed)];
self.navigationItem.rightBarButtonItem = addButton;
[self.navigationItem.rightBarButtonItem retain];
}
在我的AppDelegate的.M
然後,我添加的按鈕認爲將解決它的第二負載:
if(success){
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *control = [[ViewController alloc] initWithNibName:@"myNib" bundle:nil];
[control retain];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:control];
[navControl retain];
[self.window setRootViewController:navControl];
if (navControl.navigationItem.rightBarButtonItem == nil){
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(buttonPressed)];
navControl.navigationItem.rightBarButtonItem = addButton;
[navControl.navigationItem.rightBarButtonItem retain];
}
//[navControl release];
[self.window makeKeyAndVisible];
return;
這裏的Add按鈕在爲App委託頭的聲明和我的觀點的頭:
UIBarButtonItem *addButton;
@property (nonatomic, retain) UIBarButtonItem *addButton
其他職位說檢查viewDidLoad/viewWillAppear,但把這些代碼中的第一個代碼沒有解決問題。
經過進一步的思考,我不應該設置在AppDelegate.m文件中正確添加按鈕嗎?正如我打電話在我的視圖控制器的主要和那些作品(看到我的第一次啓動後,用戶輸入他/她的名字) – lohiaguitar91
不能回答我自己的問題,所以: 解決它自己,因爲按鈕從未添加到筆尖,初始化UIViewController沒有幫助。我不得不初始化我的視圖控制器。換句話說,替換: UIViewController * control = [[ViewController alloc] initWithNibName:@「myNib」bundle:nil]; 與: MyViewControllerClassName * control = [[MyViewControllerClassName alloc] initWithNibName:@「myNib」bundle:nil]; 希望這可以幫助其他人在未來,感謝您花時間閱讀這個,如果你做到了! – lohiaguitar91