splitview委托方法没有被调用

时间:2012-08-14 06:45:31

标签: iphone ipad

大家好我在我的ipad应用程序中使用splitviewcontroller,其中选择tableview中的每一行将显示新的detailviewcontroller,在我的一个detailview中,我再次推送一个新的detailview控制器(detailview2),并在该类(detailview2)中我定义一个协议并设置它,当按下后退按钮时,协议方法被触发,我的rootview(tableview)正在实现该协议,但是即使在设置委托后也没有调用方法。如果我在detailview1中定义相同的协议,rootview是实现然后协议方法没有在下面调用我发布代码.i不明白为什么它发生这样。任何建议将是一个很大的帮助。 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];
}

Rootview.h

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

Rootview.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;
 }

1 个答案:

答案 0 :(得分:1)

将以下代码实施到您的App Delegate方法中可能会解决您的问题。

请尝试以下代码,我认为这是致电代表的工作。

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