Znalazłem dziwne rzeczy na moim stole. Chcę utworzyć tabelę z dwiema lub więcej sekcjami, a na pierwszej sekcji chcę użyć innej niestandardowej komórki z innymi.Użyj innej niestandardowej komórki dla każdej sekcji w UITableView
Stworzyłem więc to na moim tableView:cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
if (indexPath.section == 0) {
// cell for section one
HeaderCell *headerCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!headerCell) {
[tableView registerNib:[UINib nibWithNibName:@"HeaderCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
headerCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
headerCell.labelName.text = @"First Section";
return headerCell;
}
else {
// Cell for another section
DetailCell *detailCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!detailSection) {
[tableView registerNib:[UINib nibWithNibName:@"DetailCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
detailCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
detailCell.textLabel.text = @"Another Section Row";
return detailCell;
}
}
Na pierwszym odcinku, chcę użyć headerCell
dla mojego rzędu, a następnie użyć detailCell
na innych. Ten kod działa, ale w wierszu sekcji drugiej nadal wygląda tak, jak przy użyciu headerCell
"pod" detailCell
. Dodałem etykietę do headerCell.xib
i nadal jest wyświetlana na detailCell
. Zobacz ten image.
Myślę, że wszystko to, ponieważ używam jednego identyfikatora komórki dla wszystkich sekcji. Ktoś ma rozwiązanie? Dziękuję bardzo.
tak, trzeba użyć 2 różne identyfikatory komórek. – Gandalf