1

在我的应用程序中,我解析了 Collectionview 单元格中的图像,这些单元格在按下到具有更大图像的另一个屏幕时会出现。这工作正常。但是,当我尝试将包含字符串数组的标签添加到同一个目标视图控制器时,我得到:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 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];


}

目的地VC.h

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

目的地VC.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
}

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

4

2 回答 2

2

NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xaaa7520'非常不言自明,它与发布无关,问题是你的arrayOfTiles是 aNSString而不是 a NSArray。检查您创建/分配arrayOfTiles.

于 2013-06-12T18:22:48.827 回答
0

检查你的arrayOfTitlesreleased在某些地方。检查那部分代码。但是你可以尝试arraystrong属性来设置这两个。

于 2013-06-12T16:53:40.937 回答