splitview委托方法没有被调用

问题描述:

嗨,大家好我在我的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; 
} 
+0

你的代码是一个烂摊子 - 甚至无法读取。请正确缩进 – 2014-04-17 22:08:58

将下面的代码实现到您的应用程序委托方法可能是解决您的问题。

请尝试下面的代码我认为这是调用代表的工作。

EDITED

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

我试过但没有工作 – Ghouse 2012-08-14 08:51:36

+0

现在让我试着实现我。 – 2012-08-14 09:02:28

+0

我改变了代码请尝试这个 – 2012-08-14 09:05:38