[英]IndexPath.row value is not stored
Im trying to store the indexPath.row value but on the next view Im getting 0. 我试图存储indexPath.row值,但在下一个视图我得到0。
In selectedRecipiesViewController I always get a zero. 在selectedRecipiesViewController中,我总是得到零。 Here is my code. 这是我的代码。
MainRecipieViewController.h MainRecipieViewController.h
@property (assign) int storageString ;
MainRecipieViewController.m MainRecipieViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.selectedRecipiesViewController) {
self.selectedRecipiesViewController = [[[SelectedRecipiesViewController alloc] initWithNibName:@"SelectedRecipiesViewController" bundle:nil] autorelease];
}
if(indexPath.row == 0) {
self.selectedRecipiesViewController.passingArray = soupArray;
}
if (indexPath.row == 1) {
self.selectedRecipiesViewController.passingArray = seaFoodArray;
}
if (indexPath.row ==2) {
self.selectedRecipiesViewController.passingArray = meatMuttonArray;
}
storageString = indexPath.row;
NSLog(@"storageString %i",storageString);
[self.navigationController pushViewController:self.selectedRecipiesViewController animated:YES];
[tableView reloadData];
}
SelectedRecipiesViewController.m SelectedRecipiesViewController.m
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"next view %i" ,self.vc.storageString);
}
Doesn't appear that you're setting it in the target view controller. 您似乎没有在目标视图控制器中设置它。 Also, it seems that you've created the property storageString
in the incorrect header file ( MainRecipieViewController.h
). 而且,看来你已经创建了财产storageString
不正确的头文件( MainRecipieViewController.h
)。
@property (assign) int storageString;
Then try using this before you push the view controller: 然后在推送视图控制器之前尝试使用它:
[self.selectedRecipesViewController setStorageString:indexPath.row];
Finally... 最后...
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"next view %i", self.storageString);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.