如今的APP开发中,UITableView是最常用的控件之一,而UITableView中有个很常见的效果就是勾选效果,这个效果是由UITableViewCell中的accessoryType属性来决定的 accessoryType中的变量是一个枚举值UITableViewCellAccessoryType,让我们来看一下其中包含的东西。 = oldRow) { UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath]; newCell.accessoryType cellForRowAtIndexPath:(NSIndexPath *)indexPath```中添加一段代码,解决复用问题 if (_selectPath == indexPath) { cell.accessoryType = UITableViewCellAccessoryCheckmark; }else{ cell.accessoryType = UITableViewCellAccessoryNone; }
accessoryType == UITableViewCellAccessoryType.none){ 44 cell?. accessoryType = UITableViewCellAccessoryType.checkmark 45 print(“您选择了:(cell?.textLabel?. accessoryType = UITableViewCellAccessoryType.none 48 print(“您取消选择了:(cell?.textLabel?.
cell.accessoryType = UITableViewCellAccessoryNone; // 点击行事件 -(void)tableView:(UITableView UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // 如果cell已经被标记 if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { // 取消标记 cell.accessoryType = UITableViewCellAccessoryNone ; } // 如果cell未标记 else{ // 标记cell cell.accessoryType = UITableViewCellAccessoryCheckmark
textLabel 默认蓝色,距离左边很宽的间距;detailTextLabel 贴着textLabel 4、.subtitle:textLabel在上;detailTextLabel在下一行 缩小显示 二、accessoryType
cell.textLabel.text = girl.name; cell.detailTextLabel.text = girl.verdict; // 设置单元的右边附属 // cell.accessoryType = UITableViewCellAccessoryDetailButton; // cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton ; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // 返回cell return cell;}#
models.isSelected ) { self.tintColor = HWColor(243, 39, 52); self.accessoryType = UITableViewCellAccessoryCheckmark; }else{ self.accessoryType = UITableViewCellAccessoryNone
UITableViewCellStyleValue1 UITableViewCellStyleValue2 UITableViewCellStyleSubtitle cell 右边指示样式的属性accessoryView 优先级高于accessoryType cell 右边指示样式的属性 accessoryType UITableViewCellAccessoryNone UITableViewCellAccessoryDisclosureIndicator
dequeueReusableCellWithIdentifier:@"RESULT_CELL"]; } cell.textLabel.text = self.resultsArray[indexPath.row]; cell.accessoryType
imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 1.添加iOS系统自带的cell的箭头 ``` cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator
text = games[indexPath.row] if indexPath.row == selectedGameIndex { cell.accessoryType = .Checkmark } else { cell.accessoryType = .None } return cell } 这就给包含当前选中游戏名称的单元格设置了一个对号.例如被这个app的用户赞赏的一些小的手势 accessoryType = .None } selectedGame = games[indexPath.row] //update the checkmark for the current accessoryType = .Checkmark } 不管用户何时点击一行,这个方法都被称为Table View 的代理.
UITableViewCell.init(style: UITableViewCellStyle.subtitle, reuseIdentifier: identify) if secno == 0 { cell.accessoryType text = "添加新数据..." } else { cell.accessoryType = .disclosureIndicator
UITableViewCellSeparatorStyle.SingleLine; 內边距 self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0); UITableViewCell 右侧标记 cell.accessoryType
accessoryType = UITableViewCellAccessoryType.DisclosureIndicator return cell! accessoryType = UITableViewCellAccessoryType.DisclosureIndicator return cell!
withIdentifier: identify, for: indexPath) cell.accessoryType withIdentifier: identify, for: indexPath) cell.accessoryType
UITableViewCellAccessoryDetailButton] = 48 }; contentViewWidth -= systemAccessoryWidths[cell.accessoryType UITableViewCellAccessoryDetailButton] = 48 }; contentViewWidth -= systemAccessoryWidths[cell.accessoryType
alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"formCell"]; } cell.accessoryType
UIImage(systemName: "iphone") : UIImage(systemName: "ipad") cell.accessoryType = cell.traitCollection.listEnvironment
alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } cell.accessoryType
UIImage(systemName: "iphone") : UIImage(systemName: "ipad") cell.accessoryType = cell.traitCollection.listEnvironment
shouldIndentWhileEditing; 设置编辑状态下是否显示缩进 @property (nonatomic) UITableViewCellAccessoryType accessoryType