Ios UITableViewCell以编程方式设置样式
如何创建具有下一个样式的UITableViewCell(右细节,在xib中) 例如,我可以使用下一步: cell.style=‘右细节’(粗略)Ios UITableViewCell以编程方式设置样式,ios,uitableview,Ios,Uitableview,如何创建具有下一个样式的UITableViewCell(右细节,在xib中) 例如,我可以使用下一步: cell.style=‘右细节’(粗略) 谢谢 您需要的是UITableViewCellStyleValue1,但您不能设置现有单元格的样式:您必须在创建时进行设置。像这样: UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Y
谢谢 您需要的是
UITableViewCellStyleValue1
,但您不能设置现有单元格的样式:您必须在创建时进行设置。像这样:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YourIdentifier"];
虽然这个问题的最佳答案是正确的,但它并没有触及细胞重用的话题 事实证明,您不再需要使用
tableView.register
。
相反,您可以使用以下方法:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Whenever there's a reusable cell available, dequeue will return it
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier") ??
UITableViewCell(style: .subtitle, reuseIdentifier: "cellIdentifier")
但是如果使用dequeueReuseable:forIndexPath:。。。在tableView上?如何在initWithStyle初始值设定项之外执行此操作?这会起作用吗?UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:REUSEIDENTIFIER forIndexPath:indexPath];如果(!cell){cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];}