2015-06-02 3 views
1

Почему не запускается после еще?Несколько UITableView в одном ViewController

-(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 или else if (tableView == self.tabFiveFeedbacks), запросы метода для возвращения клетки; было указано явно из уравнения ...

Добавлено NSLog проверить numberOfRowsInSection: для обоих TableView-х:

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 

Верно ли, что NSLog называют 3-4 раза для каждой секции?

+1

одно отверстие '{ 'отсутствует. вы уверены, что это ваш настоящий код? – holex

+0

Добавлено открытие { –

+0

Опубликовать весь код, чтобы было легче понять ваш вопрос. Переменная ячейки не просто появляется из ниоткуда, я уверен. – Gruntcakes

ответ

0

Вы должны сделать это так, если вы идете этим путем. А также сэм с другими делегатами.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtindexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = nil; 
    if (tableView == self.tableView1) { 
     //configure the cell for tableView1 
     cell = [tableView dequeueReusableCellWithIdentifier:@"identifierForCell1" forIndexPath:indexPath]; 
     cell.textLabel.text = @"text for cell tableView 1" 
    } else if (tableView == self.tableView2) { 
     //configure the cell for tableView2 
     cell = [tableView dequeueReusableCellWithIdentifier:@"identifierForCell2" forIndexPath:indexPath]; 
     cell.textLabel.text = @"text for cell tableView 2" 
    } else { 
     //configure the cell for any other tableView 
     //the cell object will never be nil, 
     //it will always fall back to here. 
     cell = [tableView dequeueReusableCellWithIdentifier:@"identifierForAnyOtherCell" forIndexPath:indexPath]; 
     cell.textLabel.text = @"text for any other cell" 
    } 
    return cell; 
} 

Заменить self.tableView1 с собственным Tableview (и tableView2 при необходимости)

Имейте в виду, что вы должны установить делегата из всех UITableView s к этому UIViewController

self.tableView1.delegate = self; 
self.tableView1.dataSource = self; 
self.tableView2.delegate = self; 
self.tableView2.dataSource = self; 
Смежные вопросы