0
我想更改tableview中特定单元格(按代码)的标签颜色。问题是我想使用动态单元格,导致每个单元格中的每个标签都会改变它们的颜色。这可能吗?我真的很感谢一些帮助。这是在与斯威夫特xcode。在动态tableview中更改特定单元格Swift
我想更改tableview中特定单元格(按代码)的标签颜色。问题是我想使用动态单元格,导致每个单元格中的每个标签都会改变它们的颜色。这可能吗?我真的很感谢一些帮助。这是在与斯威夫特xcode。在动态tableview中更改特定单元格Swift
我要改变它在willDisplayCell
:
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// put your logic here and then change the color as appropriate, for instance:
let row = indexPath.row
switch row {
case 0:
cell.label.color = red // pseudo code
case 2:
cell.label.color = green // pseudo code
// etc
}
}
在您的UITableViewDataSource
中,您可以使用tableView:cellForRowAtIndexPath:
在特定的indexPath
处更新该单元。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:YourCellIdentifier forIndexPath:indexPath]
if ([indexPath isEqual:theSpecificIndexPath]) {
cell.label.textColor = ...;
}
}
太感谢你了,但是你在迅速知道:)? –