我创建了三个视图控制器,FirstViewController
即SecondViewController
& ThirdViewController
。FirstViewController
推,SecondViewController
同样SecondViewController
推ThirdViewController
。
这ThirdViewController
是一个 UITableViewController。
和SecondViewController
具有ThirdViewController
自定义协议。他们都传递了一些价值来FirstViewController
使用他们各自的代表。
问题是SecondViewController
成功地将值传递给FirstViewController
,但ThirdViewController
无法做到这一点。
是不是因为SecondViewController
直接从 导航FirstViewController
,所以可以通过,ThirdViewController
没有连接,FirstViewController
所以不能通过数据?
任何帮助,将不胜感激。
编辑:
FirstViewController
只需按下SecondViewController
按钮动作。
是SecondViewController.h
:
@protocol secondViewDelegate <NSObject>
-(void)didCompleteSending:(NSArray *)array;
@end
@interface secondView : UIViewController
@property (nonatomic,strong) NSArray *footballPlayers;
@property (assign) id<secondViewDelegate>delegate;
- (IBAction)btnAction:(id)sender;
- (IBAction)btnGoToThirdView:(id)sender;
是SecondViewController.m
:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
footballPlayers = [[NSArray alloc]initWithObjects:@"Rooney",@"Van Persie",@"Ronaldo",@"Kagawa", nil];
}
- (IBAction)btnAction:(id)sender {
[delegate didCompleteSending:footballPlayers];
}
- (IBAction)btnGoToThirdView:(id)sender {
thirdView *objthirdView = [[thirdView alloc]init];
objthirdView.delegate=self;
[self.navigationController pushViewController:objthirdView animated:YES];
}
同样,我有 for ThirdViewController
。
在FirstViewController.h
-(void)didSendDetailsFromThirdView:(NSString *)colors{ NSLog(@"selected string is = %@",colors); }
-(void)didCompleteSending:(NSArray *)array{
for (NSString *str in array) {
NSLog(@"%@",str);
}
}
-(void)didSendDetailsFromThirdView:(NSString *)colors
不会从“ThirdViewController”调用。
第二次编辑
- (IBAction)btnGoToThirdView:(id)sender {
FirstViewController *objFirstViewController = [FirstViewController alloc]init];
thirdView *objthirdView = [[thirdView alloc]init];
objthirdView.delegate=objFirstViewController;
[self.navigationController pushViewController:objthirdView animated:YES];
}