2

I am new to xcode, and I try to play with UITableView to show content in array.

I try to put some array inside Feed, and try to show them in table.

but the error is hinted at this instances

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

on cell.textLabel.text = self.imageTitleArray[indexPath.row];

it says expected method to read array element not found on object of type NSArray

I am confused, why it wont read the array, captain obvious please help

this is my H files

#import <UIKit/UIKit.h>

@interface FeedTableViewController : UITableViewController
@property (strong, nonatomic) NSArray *imageTitleArray;
@end

and this is my M files

#import "FeedTableViewController.h"

@interface FeedTableViewController ()

@end

@implementation FeedTableViewController



- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
    self.title = @"Feed";
    self.imageTitleArray = @[@"Image 1",@"Image 2",@"Image 3", @"Image 4",@"Image 5"];
}
return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


}

- (void)viewDidUnload
{
    [super viewDidUnload];
    }

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

  return self.imageTitleArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  //  static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if(cell==nil){
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
  cell.textLabel.text = self.imageTitleArray[indexPath.row];    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

@end
4
  • Probably you are running it in simulator with iOS version less then 6.0. Commented Sep 14, 2013 at 8:30
  • yes mine is still at 5.1 simulator, is it not compatible then? Commented Sep 14, 2013 at 8:32
  • stackoverflow.com/questions/11425976/… Commented Sep 14, 2013 at 8:33
  • YES it is not compatible for version less than 6.0 Commented Sep 14, 2013 at 9:35

2 Answers 2

1

Try doing this for now, which will solve your problem in the short term:

cell.textLabel.text = [self.imageTitleArray objectAtIndex: indexPath.row];    

The updated syntax that you're trying to use (which is correct) came in with Xcode 4.5

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

Comments

1

cell.textLabel.text = self.imageTitleArray[indexPath.row];

here is the problem – it should be

cell.textLabel.text = [self.imageTitleArray objectAtIndex:indexPath.row];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.