1

In my app I have parsed images in Collectionview cells that segue when pressed to another screen with the larger image. This works fine. But, when I try to add a label that contains an array of strings to the same destination view controller I get :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xaaa7520'

Each array, the image and string have the same amount of indexes.

In First View Controller

-(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
}

My issue is trying to get the label to show the string, that is throwing the exception. Is there anyway I can fix this?

15
  • what is the content of your arrayOfTitles? Commented Jun 12, 2013 at 16:55
  • are you sure the problem is with your label? Commented Jun 12, 2013 at 17:03
  • arrayOfTitles contains parsed strings. The strings are showing in NSLog in original view controller. Commented Jun 12, 2013 at 17:04
  • just try this self.labelOne.text = [NSString stringWithFormat:@"%@",_string] Commented Jun 12, 2013 at 17:07
  • 2
    Your arrayOfTitles is a NSString not an NSArray Commented Jun 12, 2013 at 18:13

2 Answers 2

2

NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xaaa7520' is pretty self explanatory, it's not related to releasing, the problem is that your arrayOfTiles is a NSString and not a NSArray. Check the all the places where you are creating/assigning the arrayOfTiles.

Sign up to request clarification or add additional context in comments.

Comments

0

Check your arrayOfTitles it is being released at some places. check that part of code. But you can try to set these two array with strong property.

4 Comments

Made arrayOfTitles a strong property but still drawing exception.
have you checked the array at the place you add objects in it, try this: when all objects are added in the array , once checked it with log.
you can also try to use ViewWillAppear rather than viewDidLoad
The objects are in place. The issue seems to be in the prepareForSegue Method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.