为什么 Label Outlets 无法连接到 UITableViewCell Class
Why Label Outlets cannot be connected to UITableViewCell Class
我创建了一个 table view cell subclass 并将其设置为 prototype.I 的 class 想要将出口添加到那个 class并连接它们。
但是xcode没有回应。
下次尝试添加按钮的插座,成功了。
我想展示一张图片,可惜我没有足够的声望
我不明白为什么这个 happen.Can 有人帮助我,拜托!!
您需要为自定义 UITableViewCell
创建一个子类。之后就可以连接Label outlets了。
查看创建自定义 UITableViewCell
的精彩教程。
- 创建一个 xib 文件。删除 UIView 并拖动 UITableviewcell。
- 设置您的 UITableviewcell class 和单元格的标识符
- 拖动单元格上的组件并将它们与您的class连接起来。
在 UITableViewController 的方法 (void)viewDidLoad
上,设置:
[self.tableView registerNib:[UINib nibWithNibName:nameOfXibFile bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:identifierOfCell];
关于方法(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
,设置:
YourClassTableViewCell *cell = [tableView dequeueReusableCellWithReuseIdentifier:identifierOfCell forIndexPath:indexPath];
并设置标签的值 cell.label.text = @"Your text".
祝你好运!
要通过拖动插入引用插座,您需要在@interface 和@end 语句之间执行此操作,如属性(实际上是属性)。
你可以添加一个按钮插座,因为按钮有一个动作插座,这是方法。
我创建了一个 table view cell subclass 并将其设置为 prototype.I 的 class 想要将出口添加到那个 class并连接它们。
但是xcode没有回应。
下次尝试添加按钮的插座,成功了。
我想展示一张图片,可惜我没有足够的声望
我不明白为什么这个 happen.Can 有人帮助我,拜托!!
您需要为自定义 UITableViewCell
创建一个子类。之后就可以连接Label outlets了。
查看创建自定义 UITableViewCell
的精彩教程。
- 创建一个 xib 文件。删除 UIView 并拖动 UITableviewcell。
- 设置您的 UITableviewcell class 和单元格的标识符
- 拖动单元格上的组件并将它们与您的class连接起来。
在 UITableViewController 的方法
(void)viewDidLoad
上,设置:[self.tableView registerNib:[UINib nibWithNibName:nameOfXibFile bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:identifierOfCell];
关于方法
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
,设置:YourClassTableViewCell *cell = [tableView dequeueReusableCellWithReuseIdentifier:identifierOfCell forIndexPath:indexPath];
并设置标签的值
cell.label.text = @"Your text".
祝你好运!
要通过拖动插入引用插座,您需要在@interface 和@end 语句之间执行此操作,如属性(实际上是属性)。 你可以添加一个按钮插座,因为按钮有一个动作插座,这是方法。