Spoonshoe
Spoonshoe

Reputation: 3

NSMutable array is empty by the time Table View tries to read it

right now I'm getting and error regarding a table view cell trying to read data from an object. I am hitting a database, storing all the rows into an NSMUtable Array as object which seems to be working fine. But when I want the table view to read that array, I keep getting 'null'. Any help would be greatly appreciated.

ERROR

-[AttendeeData isEqualToString:]: unrecognized selector sent to instance 0x751ca80 2013-03-16 11:40:52.499 ExpoRequestLite[39716:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException',

@interface DashLandingViewController ()

@end

@implementation DashLandingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self){
            // Custom initialization
        }
        return self;
}

- (void)viewDidLoad {

       [super viewDidLoad];

        entries  = [[NSMutableArray alloc]init];
        _attendeeDataToPush = [[AttendeeData alloc]init];

        [self openDB];

        NSString *sql = [NSString stringWithFormat:@"SELECT * FROM data"];
        sqlite3_stmt *statement;

        if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)== SQLITE_OK) {
            while(sqlite3_step(statement) == SQLITE_ROW){
                NSLog(@"got all attendees");

               NSString *firstName = [[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];

                _attendeeDataToPush.firstNameValue = firstName;

                [entries addObject:_attendeeDataToPush];
                NSLog(@"array has %@", [[entries objectAtIndex:0] firstNameValue]);

           }
      }

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [entries count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
       NSLog(@"selected firstname is %@", [[entries objectAtIndex:0] firstNameValue]);
        cell.textLabel.text = [entries objectAtIndex:indexPath.row];
        return cell;
    }

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


@end

Upvotes: 0

Views: 162

Answers (2)

Shamsudheen TK
Shamsudheen TK

Reputation: 31339

Errors may happening here

 NSLog(@"selected firstname is %@", [[entries objectAtIndex:0] firstNameValue]);
 cell.textLabel.text = [entries objectAtIndex:indexPath.row];

Modify these lines to,

 if([entries count] > indexPath.row){

     AttendeeData *attendeeData = [entries objectAtIndex:indexPath.row];
     NSLog(@"selected firstname is %@", attendeeData.firstNameValue);
    cell.textLabel.text = attendeeData.firstNameValue;
}

Upvotes: 0

nsgulliver
nsgulliver

Reputation: 12671

Error suggests that you have error somewhere else in your code, post your complete code. From your error it seems that you are calling isEqualToString: on object which is not string type. Your code does not show where you getting the error. For Using isEqualToString: both objects should be of NSString type. If you are comparing object with string then use isEqual: instead.

Upvotes: 1

Related Questions