【问题标题】:Property 'mylabel' not found on object of type 'uitableviewcell'在“uitableviewcell”类型的对象上找不到属性“mylabel”
【发布时间】:2015-12-28 20:54:41
【问题描述】:

我正在尝试连接来自storyboard 的标签并获取此error。

在“uitableviewcell”类型的对象上找不到属性“mylabel”

在FilterDemoTableViewController.m

cell.mylabel.text = food.name;

screenshot of error in FilterDemoTableViewController.m

#import <UIKit/UIKit.h>

@interface TableViewCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *mylabel;


@end

【问题讨论】:

  • 您是否将Interface Builder中单元格的类设置为自定义类?
  • 您不能在 .h 中分配类似的属性;你的意思是.m?你能显示更多的代码。例如,如何声明cell?我的猜测是UITableViewCell * 而不是TableViewCell *
  • 是的,我有 vadian。是的,我的意思是 TableViewCell。

标签: ios objective-c iphone xcode iboutlet


【解决方案1】:

在使用cell 之前,您必须强制转换 为您的类型。

TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.mylabel.text = food.name;

现在可以正常访问了。

【讨论】:

  • 谢谢你在 cellForRowAtIndexPath 中有 UITableViewCell 而不是 TableViewCell 之前成功了
猜你喜欢
  • 1970-01-01
  • 2014-04-27
  • 2012-03-04
  • 2023-03-22
  • 2019-06-25
  • 2021-06-30
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多