嗨,大家好我在我的ipad應用程序中使用splitviewcontroller,其中選擇tableview中的每一行將顯示新的detailviewcontroller和在我的detailview我再次推動一個新的detailview控制器(detailview2)類(detailview2)我正在定義一個協議並設置它,當按下後退按鈕協議方法被解僱,我的rootview(tableview)正在實現該協議,但方法並沒有被調用,即使設置委託後.if我定義在detailview1和rootview中的相同的協議正在實現,然後協議方法不會被調用下面我發佈的代碼。我不明白爲什麼它發生這樣的。任何建議將是一個很大的幫助。 Detailview2.hsplitview委託方法沒有被調用
@protocol ModalControllerDelegate;
@interface ViewController : UIViewController<UIPopoverControllerDelegate, UISplitViewControllerDelegate>{
}
@property (nonatomic, assign) id <ModalControllerDelegate> delegate;
@end
@protocol ModalControllerDelegate <NSObject>
- (void)modalControllerDidFinish:(ViewController*)modalController;
@end
Detailview2.m
-(void)back {
// Tell the controller to go back
NSLog(@"ghhskfh");
[delegate modalControllerDidFinish:self];
[self.navigationController popViewControllerAnimated:YES];
}
Rootview.h
@interface RootViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource,ModalDelegate,ModalControllerDelegate> {
FirstDetailViewController *firstDetailViewController;
SecondDetailViewController *secondDetailViewController;
MultipleDetailViewsWithNavigatorAppDelegate *appDelegate;
}
@end
Rootview.m
- (void)viewDidLoad
{
[super viewDidLoad];
[email protected]"RootView";
self.viewcontroller=[[ViewController alloc]init];
self.viewcontroller.delegate=self;
//[self.tableView setDelegate:self];
//[self.tableView setDataSource:self];
}
#pragma mark -
#pragma mark ModalController delegate
- (void)modalControllerDidFinish:(ViewController *)modalController {
NSLog(@"modalControllerDidFinish");
}
myappdelegate.m(如有必要)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
// Add the split view controller's view to the window and display.
[window addSubview:self.splitViewController.view];
[window makeKeyAndVisible];
return YES;
}
你的代碼是一個爛攤子 - 甚至無法讀取。請正確縮進 – 2014-04-17 22:08:58