0

i want to send a message to a tableView in another controller. Actually i am in detalViewController. The tableView i want to address is in DashboardViewController:

-UIViewController
--UIView
---UITableView //i want to address this tableView.

How can i do that? In my DetailViewController IBAction i have this code:

NSLog(@"previousBtn");

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

My aim is to set the new selectRowAtIndexPath:

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

but parent.tableViews is not the correct way Thanks for help,
brush51

brush51
  • 5,691
  • 6
  • 39
  • 73

1 Answers1

1

Here is a workaround:

iam checking the subviews array and from NSLog i see the tablview was objectAtIndex:0. Then i have put that in an "if then else" and do something with the table. In my case i do selectRowAtIndexPath: and 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];
}

Hope someone can use this code and save a lot of time for try and error :)

brush51
  • 5,691
  • 6
  • 39
  • 73