通过UINavigationViewController将幻灯片菜单中的数据传递给UITableViewController
问题描述:
如何将数据从UINavigationController传递到根UITableViewController? 我已经实现了ECSlidingViewController(https://github.com/edgecase/ECSlidingViewController)。用户选择菜单中对应于不同URL的其中一个单元格,我希望显示位于UINavigationController之上的tableView上的信息。 (你知道默认组合,你得到我的拖动UINavigationController到你的故事板)。我能够从滑动菜单中获取数据到我的navigationController,现在我正试图在我的tableview上传递相同的信息?通过UINavigationViewController将幻灯片菜单中的数据传递给UITableViewController
在我的菜单我有:
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];
}
至少对我来说,我尝试过的方法都没有(在Navigation中评论过...)。请给我任何建议。先谢谢你。
答
UINavigationController
不包含任何数据,而是一堆视图控制器。我建议你查看框架,比如免费的Sensible TableView。该框架将自动处理详细视图生成并在它们之间传递数据。在我的项目中节省了大量的开发时间。
为了说明问题,你有一个'topViewController'设置为'UINavigationController',它有一个'UITableViewController'作为根视图控制器?你想从你的一个视图控制器传递数据到表视图控制器? –