如何将数据从 UINavigationController 传递到根 UITableViewController?我已经实现了 ECSlidingViewController ( https://github.com/edgecase/ECSlidingViewController )。用户在菜单中选择一个单元格,这些单元格对应于我想从位于 UINavigationController 顶部的 tableView 上显示信息的不同 url。(您知道您将 UINavigationController 拖到您的故事板的默认组合)。我现在可以从滑动菜单获取数据到我的导航控制器,现在我正在尝试在我的 tableview 上传递相同的信息?
在我的菜单中,我有:
UINavigationController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NavigationTop"];
newTopViewController = [(NavigationTopViewController*)newTopViewController initWithCinema:self.myCinema];
在 UINaviationController 中:
- (id)initWithCinema:(Cinema *)cinema {
self = [super init];
if(self) {
_myCinema = [[Cinema alloc] init];
_myCinema = cinema;
}
return self;
}
- (void) viewDidLoad {
[super viewDidLoad];
// this log works I get the info to here.
NSLog(@"url(navigation):%@", self.myCinema.cinemaURL);
//MoviesTableViewController *moviesTableViewController = [[MoviesTableViewController alloc] initWithCinema:self.myCinema];
//UITableViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MoviesTable"];
//NavigationTopViewController *newTopViewController = [[NavigationTopViewController alloc] initWithCinema:self.myCinema];
//newTopViewController = [(MoviesTableViewController *)newTopViewController initWithCinema:self.myCinema];
//[self performSegueWithIdentifier:nil sender:self.myCinema];
[self prepareForSegue:nil sender:self.myCinema.cinemaURL];
}
在我的 UITableView 中:
- (void)setCinema:(Cinema *)cinema {
// works here too
NSLog(@"Table(setCinema):%@", cinema.cinemaURL);
self.myCinema = [[Cinema alloc] init];
if(!cinema) {
cinema.cityIndex = kAstanaIndex;
cinema.name = kKeruen;
cinema.nameForText = kKeruenText;
cinema.cinemaURL = kKeruenURL;
cinema.cinemaURLTomorrow = kKeruenURLtomorrow;
}
self.myCinema = cinema;
// works here too!!!
NSLog(@"Table(myCinema):%@", self.myCinema.cinemaURL);
}
然而它在 viewDidLoad 中消失了:
- (void)viewDidLoad
{
[super viewDidLoad];
// set delegate to self
self.tableView.delegate = self;
// set loading theater's url
// does not work here: I GET NULL !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NSLog(@"url(moviesTable):%@", self.myCinema.cinemaURL);
_model = [[MovieModel alloc] initWithURL:self.myCinema.cinemaURL];
}
至少对我来说,我尝试过的任何方法(在导航中评论...)都没有。请给我任何建议。先感谢您。