user2390364
user2390364

Reputation: 11

Thread 6: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP) error using UICollectionWiew

I'm trying to populate twitter information in the collection view cells for my class assignment and each time I try to do so my app crash with this error:
Thread 6: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP)
as well as this statement shown in the debug window:
-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0xa5744b0.
What solution can I use to correct this error?
To see my entire project here is my dropbox link to the entire project.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
  // here I am creating my cell for the custom View
  CustomCollectionCellView *cellCollect = [theCollectionView dequeueReusableCellWithReuseIdentifier:@"customCell" forIndexPath:indexPath];
  if (cellCollect != nil)
 {
    NSDictionary *userTweetDictionary = [usertwitterfeed objectAtIndex:indexPath.row];
    if (userTweetDictionary != nil)
    {
        cellCollect.userNameLabel.text = (NSString *)[userTweetDictionary objectForKey:@"screen_name"];
        //cellCollect.dateLabel.text = (NSString *)[tweetDictionary objectForKey:@"created_at"];
    }
    return cellCollect;
  }

  return nil;
}

Upvotes: 1

Views: 1007

Answers (1)

Deepesh Gairola
Deepesh Gairola

Reputation: 1242

Few changes are required. First of all make usertwitterfeed an NSDictionary object instead of NSArray

then

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    // here I am creating my cell for the custom View
    CustomCollectionCellView *cellCollect = [theCollectionView dequeueReusableCellWithReuseIdentifier:@"customCell" forIndexPath:indexPath];
    if (cellCollect != nil)
    {

        if (usertwitterfeed != nil)
        {
            cellCollect.userNameLabel.text = (NSString *)[usertwitterfeed objectForKey:@"screen_name"];
        }
        return cellCollect;
    }

    return nil;
}

Upvotes: 1

Related Questions