2012-12-10 14 views
12

Przeczytałem dużo na temat tego argumentu, testowałem ten przykład, który działa: source code example. ale to nie używa storyboardów (nie wiem, czy to jest powód, dla którego mój projekt nie działa) zrobiłem inny projekt przy użyciu storyboardu, ta sama sekwencja instrukcji nie działa ...Wybrać wiersz uitableview programowo

-(void)viewDidAppear:(BOOL)animated{ 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0]; 
    [firstController.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
    [firstTable.delegate tableView:firstTable didSelectRowAtIndexPath:indexPath]; 
} 

Oto mój projekt, jest taki sam jak w poprzednim linku, tylko dodawanie viewDidAppear my not working project Czy ktoś może mi powiedzieć, co jest nie tak? dzięki

Odpowiedz

25

Próbowałem studiować kod pobraniem problemu project.The że firstController.tableView jest zerowa.
Więc go naprawić:

[firstTable selectRowAtIndexPath:indexPath 
         animated:NO 
        scrollPosition:UITableViewScrollPositionNone]; 

lub przypisać firstController.tableView do widoku tabeli.

22
- (void)viewDidLoad { 
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone]; 
} 

Jeśli chcesz zwrotnego od delegata:

if ([self.tableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) { 
    [self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 
} 
Powiązane problemy