我有一个UITableView,其中包含一个UIImage和一个UILabel的自定义单元格,紧跟在图像之后。
前三行标签必须位于'x'位置120,其他所有标签必须位于'x'位置28.
当表格加载时,所有标签都在'x'120,但是当我到达详细视图然后返回设置时,我所做的就是正常工作。问题是我需要从第一次加载表时开始工作。
我用来改变'x'位置的代码是:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CategoriesCell
switch indexPath.row {
case 0:
cell.categoryName.frame.origin.x = 120
case 1:
cell.categoryName.frame.origin.x = 120
case 2:
cell.categoryName.frame.origin.x = 120
default:
cell.categoryName.frame.origin.x = 28
cell.categoryIcon.hidden = true
break
}
return cell
}
我试图在viewWillAppear上设置为所有其他标签设置'x'位置的代码,但它不起作用。
任何人都可以知道我如何才能做到这一点?