-3

I have a storyboard with two labels in a UITableViewCell.

title and price.

In my ViewController.m I have an array with data(from a url in JSON). I get all I need BUT when I want to add this data into the label, I tried something like this:

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"BasicCell"; UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    // Get the location to be shown Location *item = _feedItems[indexPath.row]; NSString *baseUrl = @"address/to/image"; NSString *urlString = [baseUrl stringByAppendingString:item.thumbnail]; NSURL *urla = [NSURL URLWithString:urlString]; NSData * imageData = [NSData dataWithContentsOfURL:urla]; UIImage * image = [UIImage imageWithData:imageData];

    myCell.imageView.image = image;

    myCell.detailTextLabel.text = item.elementid; // "No visible @interface for 'Location' declares the selector 'objectAtIndex:' myCell.textLabel.text = item.element; //"No visible @interface for 'Location' declares the selector 'objectAtIndex:'

    return myCell; }

It does not work and I don't know why. I didn't receive any error message. Can anyone help me?

user3518279
  • 1
  • 1
  • 3

1 Answers1

1

You should add the Array text in the label at the indexPath.row

myCell.detailTextLabel.text = [item objectAtIndex:indexPath.row];
myCell.textLabel.text = [item objectAtIndex:indexPath.row];
Vaibhav Jhaveri
  • 1,579
  • 3
  • 28
  • 53
  • 1
    Or a more modern approach would be myCell.detailTextLabel.text = item[indexPath.row]; – Nick Oct 07 '14 at 12:46
  • thx very much!! i got an error ... "No visible @interface for 'Location' declares the selector 'objectAtIndex:' ... i know i know ... but i have to say i started in objective-c :) – user3518279 Oct 07 '14 at 18:48
  • @user3518279 : Make sure you are using `NSMutableArray` instead of `NSArray` – Vaibhav Jhaveri Oct 08 '14 at 04:15