我試圖在點擊應用程序中的按鈕時加載新視圖。 我得到的錯誤是 -按下按鈕時切換視圖
View Switcher[6867:207] -[UIView pushViewController:animated:]: unrecognized selector sent to instance 0x6010660
和源代碼片斷 -
-(IBAction) blueButtonPressed:(id)sender{
if(self.yellowViewController == nil){
YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
self.yellowViewController = yellowController;
//[yellowController release];
//[self.view addSubview:yellowController.view];
//[self.view pushViewController:self.yellowViewController];
[self.navigationController pushViewController:self.yellowViewController];
[yellowController release];
}
//[self.navigationController pushViewController:self.yellowViewController animated:YES];
}
這裏是我使用的頭文件 -
#import <UIKit/UIKit.h>
@class BlueViewController;
@class YellowViewController;
@interface BlueViewController : UIViewController {
YellowViewController *yellowViewController;
BlueViewController *blueViewController;
}
-(IBAction)blueButtonPressed:(id)sender;
@property(retain) YellowViewController *yellowViewController;
@property(retain, nonatomic) BlueViewController *blueViewController;
@end
鏈接到的Xcode項目是 - https://rapidshare.com/files/2403429896/View_Switcher.zip
如果您僅取消註釋if語句之外的方法調用,會發生什麼情況? –
而你的財產yellowViewController設置爲(保留)? –
最終結果是一樣的(在模擬器中沒有任何反應),但我確實得到了一個新的警告 - 不兼容的Objective-C類型結構YellowViewController *',期望'結構UIViewController *'當傳遞參數1'pushViewController:animated :'來自不同的Objective-C類型 –