我的自定義單元格的IBOutlets我做了一個XIB自定義單元格: .H不能訪問的cellForRowAtIndexPath
#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];
在d在cell
之後,Xcode告訴我「在'TWCustomCell *'類型的對象上找不到'Property'tweetText';你是否想要訪問ivar'tweetText'?「,並告訴我用 cell->tweetText.text
替換它,但是出現錯誤:」語義問題:實例變量'tweetText'受保護「。我該怎麼辦?
你可以將它們聲明爲@property – Basel
與另一個對象的實例變量混淆是醜陋的,並且非常笨拙。用'@ public'聲明它們是一種創可貼的方法,可以啓用默認情況下禁用的功能。您應該聲明('@ property')並使用('.',而不是' - >' - 即您開始的表達式)屬性。 –