2011-10-26 3 views
0

別のコントローラのtableViewにメッセージを送信したい。 実際には私はdetalViewControllerにいます。 私が対処したいのtableViewがDashboardViewControllerである:
--UIView
他のコントローラからviewController階層を歩く

-UIViewController --- のUITableView//私はこののtableViewに対処したいと思います。

どうすればいいですか?私DetailViewController IBActionで 私はこのコードを持っている:

NSLog(@"previousBtn"); 

DashboardViewController *parent = (DashboardViewController *)self.parentViewController; 
NSIndexPath *actualIndexPath = selectedRow2; 
NSIndexPath * newIndexPath = [NSIndexPath indexPathForRow:actualIndexPath.row-1 inSection:actualIndexPath.section]; 

私の目的は、新しいselectRowAtIndexPath設定することです:

[parent.tableViews selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; 

をしかしparent.tableViewsは助けを おかげで、
brush51正しい方法ではありません

答えて

1

回避方法は次のとおりです。

iam checkiサブビュー配列とNSLogから、tablviewはobjectAtIndex:0でした。それから私はそれを "それ以外の場合"に入れて、何かをテーブルでにする。とdidSelectRowAtIndexPath:

DashboardViewController *parent = (DashboardViewController *)self.parentViewController; 

NSIndexPath *actualIndexPath = selectedRow2; 
NSIndexPath * newIndexPath = [NSIndexPath indexPathForRow:actualIndexPath.row-1 inSection:actualIndexPath.section]; 
//[parent.tableViews selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; 

if([parent.view.subviews objectAtIndex:0]) { 
    NSLog(@"drin!"); 
    UIView * subview = (UIView *) [parent.view.subviews objectAtIndex:0]; 
    UITableView *tView = (UITableView *) subview; 

    [tView selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; 
    [tView.delegate tableView:tView didSelectRowAtIndexPath:newIndexPath]; 
} 

ホープ誰かがこのコードを使用し、トライアンドエラー:)

のために多くの時間を節約することができます私の場合は 私は selectRowAtIndexPathを行います
関連する問題