ios - Recreate a uitableview section dynamically on a uibutton`s click -
i need recreate uitableview section on uibutton click. here example this.
and in button click should created this.
but not able implement .
please help. creating simple uitableview textlabel.
code cellforrowatindexpath
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"simpletableitem"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier]; } cell.textlabel.text = [tabledata objectatindex:indexpath.row]; return cell; }
create integer variable index
, property tableview in .h
@property uitableview *tableview;
then in -(void)viewdidload
set index=0;
now, write method called when tap on add button
-(void)newtableview { tableview = [uitableview alloc] initwithframe:cgrectmake(x,y+height*index,width,height)]; //other code related table tableview.tag = ++index; [self.view addsubview:tableview]; }
use tag in delegate methods
edit: requested add new section in table view instead of new table view have first create table view of grouped style
tableview = [uitableview alloc] initwithframe:(cgrect)frame style:uitableviewstylegrouped];
now, when hit on add button call method
-(void)newsection { count++; [tableview reloaddata]; }
then, have implement delegate methods grouped table view
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview{ return count; } - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section { return @"title"; } - (nsinteger)tableview:(uitableview *)table numberofrowsinsection:(nsinteger)section { //same previous code } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { //same previous code }
Comments
Post a Comment