UITableView Cells Automatically Selected

My UITableView opens through PopOverViewController, so how can I load one of these cells automatically after loading the application,

cell selection process on MainViewController

- (void)setDetailItem:(id)newDetailItem {

    if (detailItem != newDetailItem) {
        [detailItem release];
        detailItem = [newDetailItem retain];

        //---update the view---
        label.text = [detailItem description];
    }

}

and cell selection in TableViewController:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    myAppDelegate *appDelegate = 
    [[UIApplication sharedApplication] delegate];
    appDelegate.viewController.detailItem = [list objectAtIndex:indexPath.row];  

}

I use this code in a TableViewController but it doesn’t work! This means that after clicking the popOver button, the code simply selects the cell!

 [myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];

I used the above code in different methods such as viewDidAppear, viewWillAppearand didSelectRowAtIndexPathand ...

thank

+2
source share
1 answer

When you call selectRowAtIndexPath:animated:scrollPosition:, it tableView:didSelectRowAtIndexPath:is not called in the delegate.

In selectRowAtIndexPath: animated: scrollPosition: link:

tableView: willSelectRowAtIndexPath: tableView: didSelectRowAtIndexPath: , UITableViewSelectionDidChangeNotification .

, selectRowAtIndexPath:animated:scrollPosition::

 [myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];

:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

if ([myTableView.delegate respondsToSelector:@selector(tableView:willSelectRowAtIndexPath:)]) {
    [myTableView.delegate tableView:self.tableView willSelectRowAtIndexPath:indexPath];
}

[myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition: UITableViewScrollPositionNone];    

if ([myTableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
    [myTableView.delegate tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}
+9

All Articles