jeudi 25 juin 2015

custom table cell displaying nil

I'm trying to set the title and display a button in my custom cell object in my second table view controller, but only my first dynamic prototype cell is displaying text.

The first prototype cell is UITableViewCell and the second is the custom object. In my first view controller I implement almost the same exact method and it works completely fine. Not sure where my error could be, the models I use have all their data in them. I have the correct cell identifier in my storyboard, and the connection from custom cell to the UIButton is set.

Thanks in advance.

Method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CellIdentifier";
    static NSString *QuestionSectionIdentifier = @"QuestionSectionCell";


    if (indexPath.section == 0) {
        UITableViewCell *cellQuestion = [tableView dequeueReusableCellWithIdentifier:QuestionSectionIdentifier];
        if (cellQuestion == nil) {
            cellQuestion = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:QuestionSectionIdentifier];
        }
        if (indexPath.row == 0) {
            cellQuestion.textLabel.text = _headerQuestion.question;
            NSLog(@"question here %@", cellQuestion.textLabel.text);
        }

        return cellQuestion;
    }

    else {
        MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
        if (indexPath.section == 1) {


            if (indexPath.row == 0) {
                [cell.firstButton setTitle:_headerQuestion.questionAuthor.fullName forState:UIControlStateNormal];
                [cell.firstButton setTag:_headerQuestion.questionAuthor.userID];
                [cell.answerLabelField setHidden:YES];

                NSLog(@"section 1  %@", cell.firstButton.titleLabel.text);

            }


        }

        else  if (indexPath.section == 2) {
                Answer* answer_num =  [_headerQuestion.answers objectAtIndex:indexPath.row]; //object at index
                [cell.firstButton setTitle:answer_num.answerAuthor.fullName forState:UIControlStateNormal];
                [cell.firstButton setTag:answer_num.answerAuthor.userID];
                cell.answerLabelField.text = answer_num.answer;

        }
        return cell;
    }

}

See more ..

Aucun commentaire:

Enregistrer un commentaire