2012-08-14 114 views
2

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

回答

1

將下面的代碼實現到您的應用程序委託方法可能是解決您的問題。

請嘗試下面的代碼我認爲這是調用代表的工作。

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

相關問題