ios - index 0 beyond bounds for empty array parse.com -
ios - index 0 beyond bounds for empty array parse.com -
i'm trying parse list of objects current user has created custom table view parse.com. i'm getting error when run it:
[__nsarraym objectatindex:]: index 0 beyond bounds empty array
here's how i'm doing it:
@interface profileviewcontroller () @property (nonatomic, retain) pfquery *query; @end @implementation dailyprofileviewcontroller - (void)viewdidload { [super viewdidload]; [self refresh]; self.tableview.delegate = self; _projects = [[nsmutablearray alloc] initwithcapacity:100]; } - (void)refresh { pfquery *query = [pfquery querywithclassname:@"projects"]; [query includekey:@"user"]; [query wherekey:@"user" equalto:[pfuser currentuser]]; [query orderbydescending:@"createdat"]; [query findobjectsinbackgroundwithblock:^(nsarray *posts, nserror *error) { if (!error) { [_projects setarray:posts]; [self.tableview reloaddata]; nslog(@"%@", posts); return; } nslog(@"fetch posts error: %@", error.localizeddescription); return; }]; } -(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming _projects.count; } -(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { homecoming 65; } -(nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming 1; } -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { _project = [_projects objectatindex:indexpath.row]; profileprojecttableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"profileprojecttableviewcell"]; if (!_user) _user = [pfuser currentuser]; cell.item = _project; [(pffile*)_project[@"profilepic"] getdatainbackgroundwithblock:^(nsdata *data, nserror *error) { cell.profilepic.image = [uiimage imagewithdata:data]; }]; [(pffile*)_project[@"bgimage"] getdatainbackgroundwithblock:^(nsdata *data, nserror *error) { cell.bgview.image = [uiimage imagewithdata:data]; }]; cell.projectname.text = _project[@"name"]; homecoming cell; } @end
please alter viewdidload this..
self.tableview.delegate = self; _projects = [[nsmutablearray alloc]init]; [self refresh];
you should phone call refresh method after intializing array , create sure info adding should not empty
ios objective-c uitableview nsmutablearray
Comments
Post a Comment