在 tableViewCellController 中声明的属性无法在 tableViewController 中访问

Properties declared in tableViewCellController cannot be accessed in tableViewController

我在我的 tableViewCellController.h.I 中声明了三个 UITextView 属性,将它们链接到故事板并将我的原型单元 class 分配给了我的 tableViewCellController。

@interface RankingsTableViewCell : UITableViewCell

@property (nonatomic, strong) IBOutlet UITextView *playerRank;
@property (nonatomic, strong) IBOutlet UITextView *playerName;
@property (nonatomic, strong) IBOutlet UITextView *playerPoints;


@end

当我试图让它们在我的 tableViewController.m 中显示文本时,我无法访问这些 UITextView 属性。我在

中这样做
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath 

我已经在 tableViewController.m

中导入了 tableViewCellController.h

提前谢谢你。

您应该做的是在 viewDidLoad 方法中注册您的 NIB,并在 cellForRowAtIndexPath 中使用它。像这样:

在 viewDidLoad 中:

NSString *myIdentifier = @"itemCellIdentifier";
[self.tableView registerNib:[UINib nibWithNibName:@"itemCellNibName" bundle:nil] forCellReuseIdentifier:myIdentifier];

应从 IB 的 UITableViewCell 属性中设置单元格标识符:

同样在 IB 中,此 UITableViewCell 的 class 名称应设置为 RankingsTableViewCell。类似下面的内容(将其替换为 SwipeableCell):

然后在 cellForRowAtIndexPath

-(RankingsTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
     static NSString *myIdentifier = @"itemCellIdentifier";

     RankingsTableViewCell *cell = (itemCell *)[tableView dequeueReusableCellWithIdentifier:myIdentifier];
     cell.playerRank.text = @"rank"; //accessing properties
     return cell;
}

就是这样。 我没有 运行 这个特别的 code-snippet,图像是从 Google 收集的。但这应该可以完成您的工作。