【发布时间】:2011-11-01 12:22:22
【问题描述】:
我用 XIB 制作了一个自定义单元格: .h
#import <UIKit/UIKit.h>
@interface TWCustomCell : UITableViewCell {
IBOutlet UILabel *nick;
IBOutlet UITextView *tweetText;
}
@end
.m
#import "TWCustomCell.h"
@implementation TWCustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
我以这种方式将它们加载到cellForRowAtIndexPath::
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TWCustomCell *cell = (TWCustomCell*)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"TWCustomCell" owner:nil options:nil];
for (id currentObject in topLevelObject) {
if([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (TWCustomCell*) currentObject;
break;
}
}
}
// Configure the cell...
cell.tweetText.text = [tweets objectAtIndex:indexPath.row];
return cell;
}
开启cell.tweetText.text = [tweets objectAtIndex:indexPath.row];
在cell 之后的点上,Xcode 告诉我_“在 'TWCustomCell *' 类型的对象上找不到属性 'tweetText';你的意思是访问 ivar 'tweetText' 吗?”并告诉我用
cell->tweetText.text。但出现错误:“语义问题:实例变量 'tweetText' 受保护”。我该怎么办?
【问题讨论】:
标签: ios cocoa-touch uitableview uikit