ios - IndexPath.row 值未存储

标签 ios objective-c properties indexing

我试图存储 indexPath.row 值,但在下一个 View 中我得到 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);
   }

最佳答案

您似乎没有在目标 View Controller 中设置它。此外,您似乎在错误的头文件 (MainRecipieViewController.h) 中创建了属性 storageString

SelectedRecipiesViewController.h

@property (assign) int storageString;

然后在推送 View Controller 之前尝试使用它:

[self.selectedRecipesViewController setStorageString:indexPath.row];

最后...

SelectedRecipiesViewController.m

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

关于ios - IndexPath.row 值未存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16155025/

相关文章:

ios - 将 NSManagedObject 重新插入到 ManagedObjectContext

c++ - 为 .dylib 文件创建 objective-c 包装器

ios - NSCache 什么时候释放缓存对象?

Python 装饰器类将方法转换为字典项

ios - ios-firebase 统一插件中的 Unity.Tasks 问题

ios - CAShapeLayer 动画(从 0 到最终大小的圆弧)

ios - 语义问题 : Cannot find the protocol declaration for ‘ARSessionDelegate’

objective-c - 如果子类引用父类(super class) ivar,则合成不相关的属性会失败

java - 有没有办法在 Spring XML 中指定默认属性值?

iphone - MPMoviePlayerController 在 iOS 7 中显示黑屏和声音,在 iOS 6 中工作正常