有人能解释一下我在下面的代码中做错了什么吗?
我尝试从didSelectRowAtIndexPath
方法传递数据,但在 SizeViewController 中,productKey的值仍为null
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
SizeViewController *sizeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SizeView"];
sizeViewController.title = [self.choosedProducts objectAtIndex:indexPath.row];
sizeViewController.productKey = [self.choosedProductsIds objectAtIndex:indexPath.row];
[[self navigationController]pushViewController:sizeViewController animated:YES];
}
答案 0 :(得分:0)
您正在尝试从故事板加载视图控制器,因此应将其初始化为
SizeViewController* detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SizeViewController storyboard identifier"];
答案 1 :(得分:0)
您可以尝试获取对故事板的引用而不是使用self.storyboard属性吗?这只是猜测。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
另外,您可以在解决方案中验证sizeViewController不是nil吗?