不存储IndexPath.row值

时间:2013-04-22 19:20:03

标签: ios objective-c properties indexing

我试图存储indexPath.row值,但是在下一个视图中我得到了0.

在selectedRecipiesViewController中,我总是得到零。这是我的代码。

MainRecipieViewController.h

@property (assign)   int storageString ;

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

- (void)viewWillAppear:(BOOL)animated {
     NSLog(@"next view %i" ,self.vc.storageString);
   }

1 个答案:

答案 0 :(得分:2)

似乎没有在目标视图控制器中设置它。此外,您似乎已在不正确的标头文件(storageString)中创建了属性MainRecipieViewController.h

SelectedRecipiesViewController.h

@property (assign) int storageString;

然后在推动视图控制器之前尝试使用它:

[self.selectedRecipesViewController setStorageString:indexPath.row];

...最后

SelectedRecipiesViewController.m

- (void)viewWillAppear:(BOOL)animated {
    NSLog(@"next view %i", self.storageString);
}