大家好,我在ipad应用程序中使用splitviewcontroller,在其中选择表视图中的每一行将显示新的detailviewcontroller,在我的detailview之一中,我再次推送新的detailviewcontroller(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];
}


根视图

@interface RootViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource,ModalDelegate,ModalControllerDelegate> {
FirstDetailViewController *firstDetailViewController;
SecondDetailViewController *secondDetailViewController;
        MultipleDetailViewsWithNavigatorAppDelegate *appDelegate;
}
@end


根视图

- (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;
 }

最佳答案

在您的App委托方法中实施以下代码可能可以解决您的问题。

请尝试下面的代码,我认为调用代表是可行的。

已编辑

 - (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;
  //Changes Made here
            self.rootViewController.firstDetailViewController=self.detailViewController;
 // Add the split view controller's view to the window and display.
            [window addSubview:self.splitViewController.view];
            [window makeKeyAndVisible];
            return YES;
  }

10-07 19:51
查看更多