我有2个自定义UITableViewCell
,并且都有属性。
虽然NSLog(@"%@", cell.class)
表明两者都是正确创建的,但我无法在tableView:cellForRowAtIndexPath:
上设置我的属性。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
if (indexPath.row != [self.realties count]) {
cell = [tableView dequeueReusableCellWithIdentifier:RealtyCellIdentifier];
NSLog(@"%@", cell.class);
cell.realtyNameLabel.text = [[self.realties objectAtIndex:indexPath.row] adTitle];
cell.realtyPriceLabel.text = [NSString stringWithFormat:@"R$%ld", [[self.realties objectAtIndex:indexPath.row] price]];
}
if (indexPath.row == [self.realties count]) {
cell = [tableView dequeueReusableCellWithIdentifier:LoadMoreCellIdentifier];
NSLog(@"%@", cell.class);
}
return cell;
}
@import UIKit;
@interface IGBRealtyCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *realtyImageView;
@property (weak, nonatomic) IBOutlet UILabel *realtyNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *realtyPriceLabel;
@end
我错过了什么?
答案 0 :(得分:1)
您使用UITableViewCell
代替IGBRealtyCell
。尝试将其转换为IGBRealtyCell变量。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
if (indexPath.row != [self.realties count]) {
cell = [tableView dequeueReusableCellWithIdentifier:RealtyCellIdentifier];
IGBRealtyCell *realtyCell = (IGBRealtyCell*)cell;
NSLog(@"%@", cell.class);
realtyCell.realtyNameLabel.text = [[self.realties objectAtIndex:indexPath.row] adTitle];
realtyCell.realtyPriceLabel.text = [NSString stringWithFormat:@"R$%ld", [[self.realties objectAtIndex:indexPath.row] price]];
}
if (indexPath.row == [self.realties count]) {
cell = [tableView dequeueReusableCellWithIdentifier:LoadMoreCellIdentifier];
IGBRealtyCell *realtyCell = (IGBRealtyCell*)cell;
NSLog(@"%@", realtyCell.class);
}
return cell;
}