ios - Reload UITableView To Contain Newly inserted Data -


i have secondviewcontroller sliding panel has uitableview , populates nsarray data returned "getnotes" function viewcontroller.running first time gets data when new data inserted uitableview not update though nsarray "n" contains new data.

here secondviewcontroller.h-

     #import <uikit/uikit.h>      @interface secondviewcontroller:uiviewcontroller<uitableviewdelegate,uitableviewdatasource>      {        nsarray *n;        }      @property (strong, nonatomic) iboutlet uitableview *tableview;      -(void)gets;      @end 

here secondviewcontroller.m-

#import "secondviewcontroller.h" #import "viewcontroller.h"   @interface secondviewcontroller ()   @end  @implementation secondviewcontroller  - (void)viewdidload { [super viewdidload]; [self gets]; }  - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }  #pragma table view methods  -(void)gets{  viewcontroller *dba=[[viewcontroller alloc]init]; n = [nsarray arraywitharray:[dba getnotes]];  }  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {   return 1; }  -(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection: (nsinteger)section{  if(n==nil)return 0;  return n.count;     }  -(uitableviewcell *)tableview:(uitableview *) tableview        cellforrowatindexpath:(nsindexpath *)indexpath{       static nsstring *cellid=@"cellid";      uitableviewcell *cell=[tableview  dequeuereusablecellwithidentifier:cellid];      if(cell==nil){            cell=[[uitableviewcell  alloc]initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellid];                   }      nsdictionary * res =[n objectatindex:indexpath.row];       cell.textlabel.text=[res objectforkey:@"notetext"];     cell.detailtextlabel.text=[nsstring stringwithformat:@"%@" ,[res   objectforkey:@"notedate"]];     return cell;    }     @end  

where problem?

update: okay..i dont know if right way or wrong called gets function , reloaded tableview inside viewwillappear method , worked :)

simple, after inserting new data in array call [tableview reloaddata]


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -