【发布时间】:2015-04-04 14:37:55
【问题描述】:
我有使用自定义单元格制作的 6 行的 tableView。
自定义单元格有一个 UILabel 和一个 UISwitch。 在“cellForRowAtIndexPath:”方法中,我有:
static NSString *CellIdentifier = @"optionsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UISwitch *optionsSwitch = (UISwitch *)[cell viewWithTag:300];
UILabel *optionsLabel = (UILabel *) [cell viewWithTag:200];
NSLog(@"%@", optionsSwitch);
NSLog(@"%@", optionsLabel);
第一次实例化 tableView 时(从情节提要)我正确地得到了两个对象(我只为表格视图的第一行添加结果):
但是当我将 reloadData 方法发送到 tableView 时(UISwitch 状态可以通过编程方式更改,因此我在显示它之前更新了 tableview)我正确地获得了 UILabel 而 UISwitch 为 nil:
为什么 UILabel 有效而 UISwitch 无效?
UISizeClasses 未启用,正如另一篇关于此问题的帖子中所建议的那样。
谢谢,科拉多
【问题讨论】:
标签: ios objective-c uitableview uiswitch viewwithtag