[英]Passing data between two table views
What I am trying to do is .. i want to pass the data between two table views. 我想做的是..我想在两个表视图之间传递数据。
In my root view controller I am using an array and then populating it for the RootViewController and in 在我的根视图控制器中,我使用一个数组,然后将其填充到RootViewController中,并在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method I am doing this: 我正在这样做的方法:
if (indexPath.row == 0)
{
self.schedule.title = @"Show1";
NSLog(@"SCHEDULE CONTROLLER TITLE = %@", schedule.title);
NSLog(@"FIRST ROW ");
}
if (indexPath.row == 1) {
self.schedule.title = @"Show2";
NSLog(@"SECOND ROW");
}
if(indexPath.row == 2){
self.schedule.title = @"Show3";
NSLog(@"THIRD ROW");
}
schedule = [[ScheduleViewController alloc] initWithNibName:@"ScheduleViewController" bundle:nil];
[self.navigationController pushViewController:schedule animated:YES];
schedule is another table view so.. what I am doing is I am comparing the titile of schedule to decide the contents of schedule table view, but some how it is not getting the data. schedule是另一个表视图,所以..我正在做的是比较日程表的标题来确定日程表表视图的内容,但是有些方法无法获取数据。
here is ViewDidLoad
method of schedule view: 这是时间表视图的
ViewDidLoad
方法:
[super viewDidLoad];
if ([self.title isEqualToString:@"Show1"])
{
showSchedule = [[NSArray alloc] initWithObjects:@"SUNDAY",@"MONDAY",@"TUESDAY" , nil];
}
if ([self.title isEqualToString:@"Show2"])
{
showSchedule = [[NSArray alloc] initWithObjects:@"WEDNESDAY",@"THURSDAY",@"FRIDAY" , nil];
}else {
showSchedule = [[NSArray alloc] initWithObjects:@"SATURDAY", nil];
}
[self.tableView reloadData];
The self.title
is returning null and therefore it goes into the else loop at the end. self.title
返回的是null,因此它最后进入else循环。 Any ideas what I am doing wrong here.. ? 有什么想法我在这里做错了吗?
Thanks for your time in advance 谢谢你的时间
try this. 尝试这个。
if ([self.title isEqualToString:@"Show1"])
{
replace this line. 替换此行。
if ([ self.navigationItem.title isEqualToString:@"Show1"])
{
Then try 然后尝试
在分配视图之前添加标题...
set your title after alloc the controller 在分配控制器后设置标题
NSString *titleOfTableVC ;
if (indexPath.row == 0)
{
titleOfTableVC = @"Show1";
NSLog(@"SCHEDULE CONTROLLER TITLE = %@", titleOfTableVC );
NSLog(@"FIRST ROW ");
}
if (indexPath.row == 1) {
titleOfTableVC = @"Show2";
NSLog(@"SECOND ROW");
}
if(indexPath.row == 2){
titleOfTableVC = @"Show3";
NSLog(@"THIRD ROW");
}
schedule = [[ScheduleViewController alloc] initWithNibName:@"ScheduleViewController" bundle:nil];
schedule.title = titleOfTableVC ;
[self.navigationController pushViewController:schedule animated:YES];
Hope this will make u understand 希望这会让你理解
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.