1

我有一个 UIViewController,它在加载时会加载这个..

MapViewController *mapController = [[MapViewController alloc] initWithNibName:@"MapView" bundle:nil];
    self.mapViewController = mapController;
    [self.view insertSubview:mapController.view atIndex:0];
    [mapController release];

我还有一个切换视图按钮,可以更改为表格视图....

if (self.tableViewController ==nil)
    {
        TableViewController *tableController = [[TableViewController alloc] initWithNibName:@"TableView" bundle:nil];
        self.tableViewController = tableController;
    [tableController release];
    //[self.view insertSubview:detailController atIndex:0];
    }

    if (self.mapViewController.view.superview == nil)
    {
        [tableViewController.view removeFromSuperview];
        [self.view insertSubview:mapViewController.view atIndex:0];
    }
    else
    {
        [mapViewController.view removeFromSuperview];
        [self.view insertSubview:tableViewController.view atIndex:0];
    }

我正在尝试根据在表视图中选择一行将视图更改为详细视图,但我根本不知道如何调用它。我所有的方法似乎都失败了!请帮忙!

4

2 回答 2

0

您应该查看用于处理行选择的类是 UITableViewDelegate,它具有以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
于 2009-05-10T08:50:30.030 回答
0

将 UITableViewDelegate 协议添加到您的控制器类。

@interface myTableViewController : UITableViewController <UITableViewDelegate>

当您创建表 veiw 控制器时,将其委托设置为您的控制器,使用:

myTableViewController.delegate = self; // Assuming your setup code runs within the table view controller

在您的 tableViewController 中,实现 didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int rowSelected = [indexPath indexAtPosition:0]; // Assuming your UITableView has a single section.
于 2009-05-10T09:04:36.830 回答