uitableview - iOS: editingStyleForRowAtIndexPath when adding a new cell -
i'm adding row uitableview section when user switches table editing mode code:
- (void) setediting:(bool) editing animated:(bool) animated { [super setediting:editing animated:animated]; if (editing) { [self.tableview insertrowsatindexpaths:[nsarray arraywithobject: [nsindexpath indexpathforrow:0 insection:section_suppliers]] withrowanimation:uitableviewrowanimationfade]; } }
the object being create "add new supplier ..." row. works, when table wants editing style can add plus or minus icon, have problem.
- (uitableviewcelleditingstyle) tableview:(uitableview *) tableview editingstyleforrowatindexpath:(nsindexpath *) indexpath { return ([self.tableview isediting] && indexpath.row == 0) ? uitableviewcelleditingstyleinsert : uitableviewcelleditingstyledelete; }
the sequence seems go this:
- the table switches editing. there 1 supplier row @ time queries editing style row == 0.
- the insert of new row done triggers query editing style again row == 0.
so if use sequence , use row number , tableview isediting decide on editing style icon end both add new , current supplier rows plus icons on them.
what best way insert row , assign appropriate editing style - plus add new row, , minus other row?
have tried putting "add new..." row @ bottom instead of @ top? instead of checking [indexpath row] == 0
instead check [indexpath row] == [items count]
, , tableview:numberofrowsinsection:
implementation looks this:
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { int numberofrows = [items count]; if ([self isediting]) { numberofrows++; } return numberofrows; }
this how example in iphone programming: big nerd ranch guide works.
Comments
Post a Comment