我已經用xib創建了自定義單元格。將CellIdendifier從XIB提供給自定義單元格
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
我想給它的單元標識符。 我試過
[email protected]"";
但它的只讀屬性。 請幫忙
我已經用xib創建了自定義單元格。將CellIdendifier從XIB提供給自定義單元格
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
我想給它的單元標識符。 我試過
[email protected]"";
但它的只讀屬性。 請幫忙
如果您在Interface Builder中創建表或單元格,那麼在創建對象時,必須在Interface Builder中設置重用標識符,因爲此屬性被設置。 只有以編程方式創建整個對象而不是在Interface Builder中創建,才能以編程方式更改(更好:設置)。
static NSString *CellIdentifier = @"YourCellName";
YourCellName *cell = (YourCellName *) [tablview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"YourCellName" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (YourCellName *) currentObject;
break;
}
}
}
我做靜態的NSString * CellIdentifier = @ 「CustomCellForAlarm」; CustomCell * cell =(CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];如果(cell == nil) { NSLog(@「New」); NSArray * topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@「CustomCell」owner:self options:nil];如果([currentObject isKindOfClass:[UITableViewCell class]]){ cell =(CustomCell *)currentObject; 休息; } } } 新單元格創建wn滾動 – Durgaprasad
對不起,我不明白 –
我用你的方式,但它每次創建單元格。從xib我給了標識符,它的工作 – Durgaprasad
- (無效)prepareForReuse –