iphone - Adding a sub row in table view cell -
this question exact duplicate of:
i working on project in making to-do-application , making on table view give functionality add button on each cell , on click of button want add child cell in hierarchy clicked cell , same cells. can please tell me how this? thankful.
thank in advance. here code:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } uibutton *button = [uibutton buttonwithtype:uibuttontypecontactadd]; button.tag = indexpath.row; button.frame = cgrectmake(280.0, 10, 25, 30.0); // x,y,width,height [button addtarget:self action:@selector(buttonclicked:) forcontrolevents:uicontroleventtouchupinside]; [cell addsubview:button]; uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc] initwithtarget:cell action:nil]; longpress.delegate = self; [cell addgesturerecognizer:longpress]; int count = 0; if(self.editing && indexpath.row != 0) count = 1; nslog([nsstring stringwithformat:@"%i,%i",indexpath.row,(indexpath.row-count)]); // set cell... if(indexpath.row == ([_choices count]) && self.editing) { cell.textlabel.text = @"add"; return cell; } nsstring *choice = [self.choices objectatindex:indexpath.row]; cell.textlabel.text = choice; return cell; }
on action of button add code
[yourtableviewobject beginupdates];
in didselectrowatindexpath , index inserted.
nsindexpath *insertpath = [nsindexpath indexpathforrow:indexpath.row insection:indexpath.section];
insert row @ indexpath :-
[yourtableviewobject insertrowsatindexpaths:[nsarray arraywithobject:insertpath] withrowanimation:uitableviewrowanimationtop]; [yourtableviewobject endupdates];
Comments
Post a Comment