【发布时间】:2013-06-12 16:44:14
【问题描述】:
在我的应用程序中,我已经解析了 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];
}
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
}
我的问题是试图让标签显示字符串,即抛出异常。无论如何我可以解决这个问题吗?
【问题讨论】:
-
你
arrayOfTitles的内容是什么? -
您确定问题出在您的标签上吗?
-
arrayOfTitles 包含已解析的字符串。字符串显示在原始视图控制器的 NSLog 中。
-
试试这个
self.labelOne.text = [NSString stringWithFormat:@"%@",_string] -
你的
arrayOfTitles是一个 NSString 而不是一个 NSArray