When empty field comes, removed the row in the Grouped Table view in iPhone? -
i have displayed datas in grouped table view. data's displayed in table view xml parsing. have 2 section of table view, section 1 has 3 rows , section 2 has 2 rows.
section 1 -> 3 rows section 2 - > 2 rows.
now want check, if of string empty should remove empty cells, have faced problems, if have removed empty cell, changed index number. how can check, of field empty?, because times more number of empty field come, index position change. please send me sample code or link that? how can achieve this?
sample code,
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { if (section == 0) { if([useremail isequaltostring:@" "] || [phonenumber isequaltostring:@" "] || [firstname isequaltostring:@" "]) { return 2; } else { return 3; } } if (section == 1) { if(![gradyear isequaltostring:@" "] || ![graduate isequaltostring:@" "]) { return 1; } else { return 2; } return 0;
}
please me out!!!
thanks.
as per understanding, dont want add row data empty, ill suggest should perpare sections data before telling table view sections , rows.
so, may following code can you..., have tested need call method "preparesectiondata" "viewdidload" method , define section arrays in .h file.
- (void) preparesectiondata { nsstring *useremail = @""; nsstring *phonenumber = @""; nsstring *firstname = @""; nsstring *gradyear = @""; nsstring *graduate = @""; sectiononearray = [[nsmutablearray alloc] init]; [self isempty:useremail]?:[sectiononearray addobject:useremail]; [self isempty:phonenumber]?:[sectiononearray addobject:phonenumber]; [self isempty:firstname]?:[sectiononearray addobject:firstname]; sectiontwoarray = [[nsmutablearray alloc] init]; [self isempty:gradyear]?:[sectiontwoarray addobject:gradyear]; [self isempty:graduate]?:[sectiontwoarray addobject:graduate]; } -(bool) isempty :(nsstring*)str{ if(str == nil || [[str stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]] length] == 0) return yes; return no; } // customize number of sections in table view. - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 2; } // customize number of rows in table view. - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { if(section == 0){ return [sectiononearray count]; } else if (section == 1) { return [sectiontwoarray count]; } return 0; } // customize appearance of table view cells. - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; } // configure cell. if(indexpath.section == 0){ cell.textlabel.text = [sectiononearray objectatindex:indexpath.row]; } else if (indexpath.section == 1) { cell.textlabel.text = [sectiontwoarray objectatindex:indexpath.row]; } return cell; }
Comments
Post a Comment