Reputation: 11197
I am trying to select a row when the table view is loaded. I've found other thread regarding this issue but they didn't solve my problem so I am asking again.
My tableview contains 5 row. And I am doing this:
if ([[dataSource objectAtIndex:indexPath.row] isEqualToString:self.status]) {
[self tableView:[self tableView] didSelectRowAtIndexPath:indexPath];
}
I've also tried cell.selected = YES;
and cell.highlighted = YES;
.
I am using the following code for custion selection view:
UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = [UIColor colorWithRed:180/255.0
green:138/255.0
blue:171/255.0
alpha:0.5];
cell.selectedBackgroundView = customColorView;
Please help me selecting a row programmatically. The row is selected when I tap on the row, but can not select programmatically.
Upvotes: 1
Views: 1869
Reputation: 1249
You can get this by calling UITableView
delegate method which is
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {}
inside this method you need to check every selected time that same cell are you not tapped.
if ([[myArray objectAtIndex:indexPath.row] isEqualToString:self.same])
{
[myTable selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}
Upvotes: 3
Reputation: 47049
Try with following code
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
Here you need to set indexPath
for row that you want to be selected.
Upvotes: 3
Reputation: 1394
Try calling selectRowAtIndexPath on the table view object:
if ([[dataSource objectAtIndex:indexPath.row] isEqualToString:self.status])
{
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}
Upvotes: 1