大家好,我在我的 ipad 应用程序中使用 splitviewcontroller,在其中选择 tableview 中的每一行将显示新的 detailviewcontroller 并且在我的一个 detailview 中我再次推送一个新的 detailview 控制器(detailview2)并且在那个类(detailview2)中我正在定义一个协议和设置它并且当按下后退按钮时协议方法被触发并且我的rootview(tableview)正在实现该协议但是即使在设置委托之后方法也没有被调用。如果我在detailview1中定义了相同的协议并且rootview正在实现那么协议方法在下面没有被调用我发布代码。我不明白为什么会这样。任何建议都会有很大帮助。Detailview2.h
@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];
}
根视图.h
@interface RootViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource,ModalDelegate,ModalControllerDelegate> {
FirstDetailViewController *firstDetailViewController;
SecondDetailViewController *secondDetailViewController;
MultipleDetailViewsWithNavigatorAppDelegate *appDelegate;
}
@end
根视图.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title=@"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;
}