我有两个viewcontrollers。一个包含一个tableview。在didselectrowforindexpath方法中,我想将一个对象发送到另一个视图控制器,但是当它传递给目标视图控制器时该对象为空。
im发送的对象是属于TableServiceNews类的service_ID。目标viewcontroller继承TableServiceNews。
以下是didselectrow的代码: -
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TableServiceNews *serviceTable = [[TableServiceNews alloc]init];
serviceTable.service_ID = [ServiceID objectAtIndex:indexPath.row];
serviceTable = [self.storyboard instantiateViewControllerWithIdentifier:@"navigationServiceNews"];
[self.slidingViewController anchorTopViewOffScreenTo:ECRight
animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;
self.slidingViewController.topViewController = serviceTable;
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];
}];
}
slideviewcontroller方法使用的是我从github获得的类,https://github.com/edgecase/ECSlidingViewController是链接。
答案 0 :(得分:0)
确保在实现中定义了service_ID(@synthesize),如果它不起作用,请确保在推送新的viewcontroller以首先加载它之后为其赋值。 我希望这很有帮助
答案 1 :(得分:0)
替换:
TableServiceNews *serviceTable = [[TableServiceNews alloc]init];
serviceTable.service_ID = [ServiceID objectAtIndex:indexPath.row];
serviceTable = [self.storyboard instantiateViewControllerWithIdentifier:@"navigationServiceNews"];
with:
UIViewController *serviceTable = [self.storyboard instantiateViewControllerWithIdentifier:@"navigationServiceNews"];
((TableServiceNews*)serviceTable).service_ID = [ServiceID objectAtIndex:indexPath.row];
问题可能是在从storyboard实例化serviceTable之前分配service_ID值。
顺便说一句,instantiatViewControllerWithIdentifier返回一个UIViewController。所以你需要将它转换为像你创建的子类一样使用它。