从“子视图”调用 UIViewController

发布于 2024-07-18 13:37:59 字数 1077 浏览 3 评论 0原文

我有一个 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];
    }

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

I have a UIViewController which when it loads it loads up this..

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

I also have a switch views button that can change to a table view....

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];
    }

I am trying to change the view to a detail view based on selecting a row in the table view and I cannot work out how to call it at all. All methods I have seem to fail! Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经暖 2024-07-25 13:37:59

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

@interface myTableViewController : UITableViewController <UITableViewDelegate>

当您创建表视图控制器时,使用以下方法将其委托设置为您的控制器:

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.

Add the UITableViewDelegate protocol to your controller class.

@interface myTableViewController : UITableViewController <UITableViewDelegate>

When you create your table veiw controller set its delegate to be your controller using:

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

In your tableViewController, implement didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int rowSelected = [indexPath indexAtPosition:0]; // Assuming your UITableView has a single section.
早茶月光 2024-07-25 13:37:59

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

The class you should look at for handling row selection is UITableViewDelegate, which has the method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文