ios - Multiple UITableView in one ViewController -
why not triggered after else?
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { if (tableview == self.tabfourcontacts) { static nsstring *cellidentifier = @"contactcell"; contactcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; if ([self.contactsarray[indexpath.row] hasprefix:@"tel_"]){ cell.labelcontact.text = [self.contactsarray[indexpath.row] stringbyreplacingoccurrencesofstring:@"tel_" withstring:@""]; cell.iconcontact.image = [uiimage imagenamed:@"ic_tab4_contacts_phone.png"]; } ... if ([self.contactsarray[indexpath.row] hasprefix:@"addr_"]){ cell.labelcontact.text = [self.contactsarray[indexpath.row] stringbyreplacingoccurrencesofstring:@"addr_" withstring:@""]; cell.iconcontact.image = [uiimage imagenamed:@"ic_tab4_contacts_address.png"]; cell.selectionstyle = uitableviewcellselectionstylenone; } return cell; } else { static nsstring *cellidentifier = @"feedbackcell"; feedbackcell * cellfeedback = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; feedback * feedbackobject; feedbackobject = [feedbacksarray objectatindex:indexpath.row]; cellfeedback.feednamelabel.text = feedbackobject.name; cellfeedback.feeddatelabel.text = feedbackobject.date; cellfeedback.feedtextlabel.text = feedbackobject.feedback; if ([feedbackobject.isgood isequaltostring:@"1"]) { cellfeedback.feedimageview.image = [uiimage imagenamed:@"ic_ratingup_green.png"]; } if ([feedbackobject.isgood isequaltostring:@"0"]) { cellfeedback.feedimageview.image = [uiimage imagenamed:@"ic_ratingdown_red.png"]; } return cellfeedback; } }
if second case specify if
or else if (tableview == self.tabfivefeedbacks)
, method requests return cell; stated out of equation...
added nslog check numberofrowsinsection:
both tableview's:
2015-06-02 22:41:08.052 myapp[27994:1093141] numrowsfortab1: 0 2015-06-02 22:41:08.052 myapp[27994:1093141] numrowsfortab1: 0 2015-06-02 22:41:08.053 myapp[27994:1093141] numrowsfortab2: 0 2015-06-02 22:41:08.053 myapp[27994:1093141] numrowsfortab2: 0 2015-06-02 22:41:08.061 myapp[27994:1093141] numrowsfortab2: 0 2015-06-02 22:41:08.061 myapp[27994:1093141] numrowsfortab1: 0 2015-06-02 22:41:08.217 myapp[27994:1093141] numrowsfortab1: 1
is correct nslog call 3-4 times each section?
you should this, if go way. , sam other delegates.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = nil; if (tableview == self.tableview1) { //configure cell tableview1 cell = [tableview dequeuereusablecellwithidentifier:@"identifierforcell1" forindexpath:indexpath]; cell.textlabel.text = @"text cell tableview 1" } else if (tableview == self.tableview2) { //configure cell tableview2 cell = [tableview dequeuereusablecellwithidentifier:@"identifierforcell2" forindexpath:indexpath]; cell.textlabel.text = @"text cell tableview 2" } else { //configure cell other tableview //the cell object never nil, //it fall here. cell = [tableview dequeuereusablecellwithidentifier:@"identifierforanyothercell" forindexpath:indexpath]; cell.textlabel.text = @"text other cell" } return cell; }
replace self.tableview1
own tableview (and tableview2 if needed)
keep in mind should set delegate of uitableview
s uiviewcontroller
self.tableview1.delegate = self; self.tableview1.datasource = self; self.tableview2.delegate = self; self.tableview2.datasource = self;
Comments
Post a Comment