如何默认选择UITableViewCell?

use*_*857 17 iphone cocoa-touch uitableview ios

我已经创建了一个UITableView并希望UITableViewCell在加载视图时显示选中(蓝色)的特定内容.

Haf*_*hor 41

-(void)viewWillAppear:(BOOL)animated {
    // assuming you had the table view wired to IBOutlet myTableView
    // and that you wanted to select the first item in the first section
    [myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] 
                             animated:NO 
                       scrollPosition:UITableViewScrollPositionTop];
}
Run Code Online (Sandbox Code Playgroud)

我正在使用这种技术来选择两个中的一个,UITableViewCells以便用户知道UIDatePicker它将影响表格视图下方的哪个单元格.当您创建新事件并设置日期时,Apple会在日历应用中使用此技术.


Sha*_*rog 6

使用这种方法要明智,因为以这种方式选择行是Apple建议不要做以显示"选择"状态.

相反,考虑将单元格的accessoryType属性设置为类似的东西 UITableViewCellAccessoryCheckmark.


Dan*_*iel 0

使用 UITableViewCell 方法

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)

信息在这里