开发者

how to edit property of UITableViewCell on other method

开发者 https://www.devze.com 2022-12-17 08:35 出处:网络
i know it will be setup cell on this method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat开发者_如何学Ch

i know it will be setup cell on this method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat开发者_如何学Ch

for example if i want to edit property of cell in

tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

how can i access to the cell that i selected?


You can get visible cell in UITableView using following method:

-(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

Return Value: An object representing a cell of the table or nil if the cell is not visible or indexPath is out of range.

So in your didSelectRow method you will have something like (you may need to set cell's selectionStyle to UITableViewCellSelectionStyleNone to make your changes display properly):

- tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell != nil){
        cell.textLabel.textColor = [UIColor redColor];
    }
}

Or you can subclass UITableViewCell, implement - (void)setSelected:(BOOL)selected animated:(BOOL)animated method and change cell properties there.

0

精彩评论

暂无评论...
验证码 换一张
取 消