问题描述
|
如何在UITableViewCell上具有标签,但在其最右侧具有箭头?
这是我尝试的:
} else if(indexPath.row == 1) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,200,21)];
label.text = @\"Select to change code\";
label.tag = 1;
label.textColor = [UIColor grayColor];
cell.accessoryView = label;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
但这不起作用。我看到标签,但在单元格最右侧看不到箭头。
解决方法
尝试以下方法:
else if(indexPath.row == 1) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,200,21)];
label.text = @\"Select to change code\";
label.tag = 1;
label.textColor = [UIColor grayColor];
[cell addSubview:label];//i changed oonly this line
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
希望对您有帮助........
编辑:(因为我无法发表评论。进行细微更改的原因是在您的原始代码中,您已将标签添加到单元格中,作为其的附件类型subView(有效地用标签覆盖了它),而在修改后的代码中,标签已正确添加为单元的单独子视图。
, 您不能同时具有cell.accessoryType获得的定制附件视图和系统提供的视图。这个怎么样:
cell.textLabel.text = @\"Select to change code\";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;