简体   繁体   中英

How can set the background view of a UITableViewCell to the selected background when it is not selected?

I created a custom implementation of a multi-selectable table view. Multiple rows can be selected programatically. The only part I haven't been able to figure out is how to programatically set the background view of cell to the default system cell selected color/pattern.

Does anyone know how to do this?

Thanks!

Could you please post your method:

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

Same code can help to understand the problem :)

Are you asking how to programatically select rows?

If so, then use the 'selectRowAtIndexPath:animated:scrollPosition:' method call, or create the cell with

cell.selected = YES;

For the first cell, set it to selected as normal. For other cells, get the class of the backgroundView of the first selected cell, instantiate a new object of that class, and assign it as the background view.

otherCell.backgroundView = [[[[[firstCell backgroundView] class] alloc] init] autorelease];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM