2011-09-28 21 views
1

UITableviewUIPopovercontrollerにメニューがあります。これを選択すると、親ビューのUIScollViewが特定のフレームにスクロールされます。selectRowAtIndexPathがviewWillAppearに失敗しました

素晴らしいです。

あなたは、私が現在pageControl.currentPage

ないエラーを返し[_delegate returnPageNumber]テーブルで選択した行を更新する必要があるフレームをスクロールするpageControlを使用する場合の問題は、のNSLogが正しいページ番号を報告しているされています

scrollIndexPath is <NSIndexPath 0x1a3380> 2 indexes [0, 3] 

しかし、正しいセルは強調表示されません。なぜですか?

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    //[tableView reloadData]; 
    int isPage = [_delegate returnPageNumber]; 
    NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:(isPage) inSection:0]; 
    NSLog(@"scrollIndexPath is %@",scrollIndexPath); 
    [tableView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];  
} 

私は前と後[tableView reloadData]を置くとviewDidAppearでコードを有する試してみた...何も今働い

+0

をお-didSelectRowAtIndexPathを使用していないのはなぜ? – CodaFi

答えて

0

を働きません!

違いを起こしたのはビューアウトレットを切断してから、それをテーブルビューに再接続することでした。なぜこれが違いになったのか分かりませんか?ペン先にView Controllerを追加しようとしましたが、違いはありません。そのため、ビューを削除してtableviewに再接続すると、結果が突然生成されました。ブードゥー。

2

viewWillAppearで、他のすべての後に[super viewWillAppear]を呼び出してみてください。

- (void)viewWillAppear:(BOOL)animated 
{ 

    NSIndexPath *selection = [self.tableView indexPathForSelectedRow]; 

    [[self tableView] reloadData];  


    if (selection) 
    { 
     [[self tableView] selectRowAtIndexPath:selection animated:NO scrollPosition:UITableViewScrollPositionNone];   
    } 

    [super viewWillAppear:animated]; //Trick is calling super last in this case. Then you can retrieve previously selected row to --> NSIndexPath *selection 

} 
関連する問題