通过TabBar链接两个TableView

时间:2012-06-22 16:05:24

标签: ios xcode xcode4 uitabbarcontroller xcode-storyboard

我有两个视图,AlllocationsViewControllerLoactionsViewController相互关联。

这就是它在故事板中的表现:

enter image description here

AlllocationsViewController的每个单元格都链接到LocationsViewController并向其发送一些数据,以便在tableView中查看:AlllocationsViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    LocationsViewController *locationsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LocationsViewController"];

    //Will send the data from the cell to the next view into 'locationlink', which is set as property in LocationsViewController.h to retrieve the data
    locationsViewController.locationlink = cell.detailTextLabel.text;   

    [self.navigationController pushViewController:locationsViewController animated:YES];

} 

现在我想通过这些视图放置一个TabBar:

enter image description here

插入数据后,如果我保留下面的代码,TableCell会将用户发送到TableView(LocationsViewController),但不显示TabBar。 我需要在下面的代码中更改什么才能显示TabBar?我现在必须链接到TabBar而不是locationsViewController吗?或者我是否必须在LocationsViewController中设置TabBar? 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

也许这有点晚了,但我想我可以帮到你。

我更喜欢使用PrepareForSegue,但在你的情况下你可以使用这样的东西......

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    ClassTabBar *TabBarController = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarClientes"];
    Locations *locationViewController = [TabBarController.viewControllers objectAtIndex:0]; // you can use the index you need
    locationViewController.locationlink= cell.detailTextLabel.text;  
    [self.navigationController pushViewController:TabBarController animated:YES];
}

告诉我是否可以帮助你做其他事情