尝试将字符串数组传递给目标视图控制器

时间:2013-06-12 16:44:14

标签: ios arrays string segue

在我的应用程序中,我已经解析了Collectionview单元格中的图像,这些图像在按下到较大图像的另一个屏幕时会发生偏移。这很好用。但是,当我尝试将包含字符串数组的标签添加到同一个目标视图控制器时,我得到:

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFString objectAtIndex:]:无法识别的选择器发送到实例0xaaa7520'

每个数组,图像和字符串都有相同数量的索引。

在第一视图控制器中

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"BottomSegue"]) {
    //DetailShowImageViewController *detailedVC = segue.destinationViewController;
    //detailedVC.detailImageView  =sender;


    NSArray *indexPaths = [self.bottomCollectionview indexPathsForSelectedItems];
    NSLog(@"%@", indexPaths);
    BottomCollectionDetail *destinationVC =segue.destinationViewController;
    NSIndexPath *indexPath = [indexPaths objectAtIndex:0];
    NSLog(@"%@", indexPath);

    destinationVC.imageFromArray  = [bottomArray objectAtIndex:indexPath.row];
    destinationVC.string = [arrayOfTitles objectAtIndex:indexPath.row];
    [self.bottomCollectionview deselectItemAtIndexPath:indexPath animated:YES];


}

destinationVC.h

@property (weak, nonatomic) IBOutlet UILabel *labelOne;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewBCD;
@property(weak, nonatomic) NSString *string;
@property(weak, nonatomic)UIImage *imageFromArray;

destinationVC.m

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.
    self.imageViewBCD.image = _imageFromArray;
    self.labelOne.text = _string; //This is the line of code that is causing exception
}

我的问题是尝试让标签显示字符串,即抛出异常。无论如何我可以解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xaaa7520'非常自我解释,与发布无关,问题是您的arrayOfTilesNSString而不是NSArray。检查您正在创建/分配arrayOfTiles的所有位置。

答案 1 :(得分:0)

在某些地方检查arrayOfTitles它是released。检查那部分代码。但您可以尝试将这两个array设置为strong属性。