Xcode 4.2 UITableview自定义单元格 [英] Xcode 4.2 UITableview Custom cell
本文介绍了Xcode 4.2 UITableview自定义单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
故事板上的自定义单元格有问题。我需要从名为
I have a problem with Custom cell on story board. I need to access labels from the method called
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
如何在我的代码中定义它?当我使用IBOutlet然后它可能导致错误。
How can i define it in my code? When I used IBOutlet Then It may caused the error.
那么我怎样才能访问标签,如
So how could I access the label like
cell.textlable.text ??
cell.textlable.text ??
非常感谢。
推荐答案
一个常见的解决方案是在故事板中为每个标签添加标签,然后找到标签使用 viewWithTag:
在你的代码中找到它,如下所示:
One common solution is to give each label a tag in the storyboard, and then find the label using viewWithTag:
to find it in your code, like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = blah blah blah ...
...
UILabel *myLabel = [cell viewWithTag:1];
UILabel *anotherLabel = [cell viewWithTag:2];
// etc.
}
这篇关于Xcode 4.2 UITableview自定义单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文