2011-10-26 38 views
0

我想將消息發送到另一個控制器中的tableView。 其實我在detalViewController。 的的tableView我想解決的是在DashboardViewController:從其他控制器中瀏覽viewController層次結構

-UIViewController
--UIView
--- 的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 ng subviews數組和NSLog我看到tablview是objectAtIndex:0。然後我把它放在「if then else」中,並且與表格做一些事。 在我來說,我做selectRowAtIndexPath: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]; 
} 

希望有人可以使用此代碼,節省了大量的時間,嘗試和錯誤:)

相關問題