简体   繁体   中英

NSArray not loading UITableView

I have the following NSArray

(
"<Events:pxhQQ5wqBz:(null)> {\n    EventName = \"Volunteer Fiar\";\n    School = \"<School:9CbVOFj1be>\";\n    SchoolName = \"Quinnipiac University\";\n}",
"<Events:x06pKsCIxm:(null)> {\n    EventName = \"QU vs Yale\";\n    School = \"<School:9CbVOFj1be>\";\n    SchoolName = \"Quinnipiac University\";\n}",
"<Events:Cc3KQLY9MR:(null)> {\n    EventName = \"Bobcat Madness\";\n    School = \"<School:9CbVOFj1be>\";\n    SchoolName = \"Quinnipiac University\";\n}"
)

I am trying to add an item from that array into a label in my UITableView and it seems to crash my application. Any ideas why? I keep getting the following crash:

-[__NSArrayI length]: unrecognized selector sent to instance 0x10d923bc0

Here is my code

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

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

   cell.textLabel.text = [self.eventArray valueForKey:@"EventName"];
} 

To clarify some, the amount of rows that are supposed to be returned is correct. I just cannot seem to get EventName in the textLabel object.

Assuming you have an object of type Event stored in the eventArray, and that Event object has a property EventName , you need to get the event associated with that row first , and then you can set event's name on the cell.

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

   // do all your normal cell creation/reuse stuff here...

   Event *eventForRow = self.eventArray[indexPath.row];
   cell.textLabel.text = eventForRow.EventName;

   return cell;
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM