2013-10-22 46 views
2

我有一个初始的ViewController,我们称之为HomeViewController,它有一个调用模态视图控制器的按钮,可以称它为ModalViewController。在那个ModalViewController里面我有两个部分的表格视图。如果您单击第0部分中的任何单元格,则会将信息发送回HomeViewController(这部分我已使用协议)。如果您点击第1部分中的任何单元格,则会将其推送到具有选项的另一个视图控制器,我们可以将其称为OptionsViewController。这里对我来说很棘手。如果您点击其中的任何选项,请关闭OptionsViewController并关闭ModalViewcontroller,并将该信息发送到HomeViewController,就像ModalViewControllerHomeViewController一样。我试图建立一个类似于ModalViewController中的协议,但它永远不会被调用。使用模态视图控制器设置协议 - > ViewController

OptionsViewController协议& .h文件中

@protocol OptionsViewControllerDelegate <NSObject> 
@optional 
-(void) optionsInfo:(NSArray *)optionsViewArray; 

@end 

@interface OptionsViewController : UITableViewController 
@property (retain) id delegate; 
@property (nonatomic, strong) NSArray *sendArray; 
@end 

OptionsViewController.m那里它被称为弹出堆栈。

{ 
    [self dismissOptionsView]; 
} 
-(void) viewWillDisappear:(BOOL)animated 
{ 
    NSLog(@"Send Array: %@", self.sendArray); 
    [[self delegate] optionsInfo:sendArray]; 
} 
-(void)dismissOptionsView 
{ 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

内ModalViewController.h

@protocol ModalViewControllerDelegate <NSObject> 
@optional 
-(void) sendInformation:(NSArray *)infoArray; 
@end 

@interface ModalViewController : UITableViewController <ConditionsViewControllerDelegate, UISearchBarDelegate> 
{ 
    UISearchBar *searchDrugBar; 
} 
@property (retain) id delegate; 
@property (nonatomic, strong) IBOutlet UISearchBar *searchDrugBar; 
@property (nonatomic, strong) NSArray *infoArray; 
@end 

ModalViewController.m其中OptionsInfo应该进来了。

-(void) optionsInfo:(NSArray *)optionsViewArray 
{ 
    //IT NEVER REACHES HERE :(
    NSLog(@"HERE"); 
    self.infoArray = optionsViewArray; 
    NSLog(@"Finished"); 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

有没有人做过类似这样的事情还是知道的解决方案这个?任何信息,链接,指导等,以正确的方向将不胜感激。提前致谢。

回答

0

您需要设置委托下面的OptionsViewController: -

在你OptionsViewController.m包括下列行的方法

[self setDelegate:ModalViewController]; 
+0

以下哪种方法? '[self dismissOptionsView];'或'[[self delegate] optionsInfo:sendArray];'。同样使用'ModalViewController'意味着我将不得不''在OptionsViewController.h内部#import“ModalViewController.h”,正确吗?我认为我们不允许使用Protocols来做到这一点,关于递归所有权或类似的东西。 – Chris

+0

是的正确你必须导入ModalViewController.h,因为直到除非你不会设置委托。您的方法不会被调用 –

+0

完成。现在我收到一个错误:'找不到'OptionsViewControllerDelegate'的协议声明,你的意思是'UISplitViewControllerDelegate'?我在@界面上获取了@ @ property(nonatomic,unsafe_unretained)id delegate1上的ModalViewController &&的错误信息''不知道有什么关于? – Chris

相关问题