ios - NSMutableArray property is not working in dequeueReusableCellWithIdentifier -


i have view controller has tableview embedded inside of it. have following code.

@property (nonatomic, strong) nsmutablearray* eventarray;  - (void)viewdidload {      [super viewdidload];     self.eventtableview.delegate = self;     self.eventtableview.datasource = self;       if (!self.eventarray){         self.eventarray = [[nsmutablearray alloc] init];      }      ...      for(nsdictionary* dict in responseobject){              [self.eventarray addobject:[[event alloc] initwitheventname:[dict valueforkey:@"name"]eventdescription:[dict valueforkey:@"description"]]];         }      [self.eventtableview reloaddata]; }    - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {      for(event* event in self.eventarray)     {         nslog(@"event name in numberofrows: [%@]", [event eventname]);     }     return [self.eventarray count]; }    - (uitableviewcell *)tableview:(uitableview *)tableview      cellforrowatindexpath:(nsindexpath *)indexpath {    static nsstring *myidentifier = @"eventcell";      eventtableviewcell *cell = [tableview dequeuereusablecellwithidentifier:myidentifier];      event* eventforcell = (event*)[self.eventarray objectatindex:[indexpath row]];      nslog(@"eventarraysize [%lu]", [self.eventarray count]);      for(event* event in self.eventarray)     {         nslog(@"event name: [%@]", [event eventname]);     }       [cell.eventnamelabel settext: [eventforcell eventname]];     return cell; } 

as code running through see objects added eventarray successfully, , log loop print in numberofrowsinsection prints following

event name in numberofrows: [worship rehearsal] event name in numberofrows: [worship rehearsal] event name in numberofrows: [worship rehearsal] 

the same loop in cellforrowatindexpath prints out following

eventarraysize [3] event name: [(null)] event name: [(null)] event name: [(null)] 

i have tried other properties , able access them correctly. help.

the name of event nil. it's because there problem when initialize array.

this wrong[dict valueforkey:@"name"]

use [dict objectforkey:@"name"]

or dict[@"name"]


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -