當完成按鈕應用程序的點擊崩潰並給出程序收到信號SIGABRT的消息時。在解除來自UINavigation Controller的modalviewcontroller的問題完成按鈕
在ModalViewController.h委派協議和方法
@protocol ModalViewDelegate <NSObject>
-(void) dismissModalView:(UIViewController *) viewController;
@end
@interface Infoviewcontroller : UIViewController <ModalViewDelegate>
{
id<ModalViewDelegate> dismissDelegate;
}
@property (nonatomic, retain) id<ModalViewDelegate> dismissDelegate;
@end
在modalviewcontroller。米文件
@synthesize dismissDelegate;
-(void) dismissModalView:(UIViewController *) viewController;
{
[self dismissModalViewControllerAnimated:YES];
}
@end
在完成按鈕定義
UIButton* backButton = [UIButton buttonWithType:101];
[backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"Done" forState:UIControlStateNormal];
// create button item
UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
// add the button to navigation bar
self.navigationItem.leftBarButtonItem = backItem;
[backItem release];
-(void) dismissView: (id)sender
{
[UIViewController dismissDelegate];
}
當完成按鈕的應用程序崩潰的點擊次數和給出節目接收信號SIGABRT消息。所以我認爲我做錯了dismissView完成按鈕的方法,這就是爲什麼它給出的消息,UIViewController dismissDelegate無法識別的選擇器
幫助將不勝感激。
感謝
非常感謝您花時間詳細解釋。 – user1120133 2012-01-15 20:54:35
作爲進一步的評論,請注意iOS5.0之前的模態視圖控制器沒有'presentationViewController',並且不會對這個選擇器做出響應。在iOS5.0中,Apple也將'parentViewController'的返回值(!)更改爲'nil'。 – SK9 2012-01-16 22:10:02