如果您使用reuseIdentifier:
初始化單元並在表視圖上使用dequeueReusableCellWithIdentifier:
方法,則表格視圖單元格將始終重新使用。
至於是否使用單個UITableViewCell
的子類或幾個,取決於您的9種內容類型之間有多少差異。如果它們都包含相同的UI元素,則使用1個子類是有意義的。否則,只要您爲每個子類傳入不同的唯一標識符,您就可以創建多個子類,並仍然可以重複使用dequeueReusableCellWithIdentifier:
中的單元格。每個子類都將獨立重用。
這是你的cellForRowAtIndexPath:
可能是什麼樣子,如果你使用多個小區類別:如果您使用tableView.dequeueCell
NSString *primaryCellID = @"PrimaryCellID";
NSString *secondaryCellID = @"SecondaryCellID";
if (someCondition) {
CustomTableViewCell1 *cell = [tableView dequeueReusableCellWithIdentifier:primaryCellID];
if (!cell) {
cell = [[CustomTableViewCell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:primaryCellID];
}
return cell;
}
else {
CustomTableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:secondaryCellID];
if (!cell) {
cell = [[CustomTableViewCell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondaryCellID];
}
return cell;
}
細胞會被重用,不管你已經在你的所作所爲 –
邏輯是你的,我應該使用9種不同類型的細胞,並根據條件,單細胞中使用的相同條件以及基於條件改變高度,我們不知道您的項目包含什麼,自定義 –