单击 tableCell 后加载子视图

发布于 2024-11-30 13:44:06 字数 715 浏览 0 评论 0原文

所以我试图在我当前的 Xcode 项目中添加一个表视图,每当您单击一个单元格(无论是哪个单元格)时,都会将一个新的子视图添加到窗口中。我将使用全局变量和 didSelectRowAtIndexPath 来传递数据。

就目前情况而言,我在屏幕上绘制了表格视图,其中包含正确的数据。我想要发生的是,当我单击时,会添加一个新的子视图,但我似乎无法让它工作。

我尝试在 didSelectRowAtIndexPath 方法本身中添加“addSubview”,但这不起作用,我尝试声明一个单独的方法来加载名为“loadDetails”的子视图,然后在选择单元格时使用 [self loadDetails] 调用它,但它想要调用后的 id,我不知道要传入什么。

我在项目的其他地方使用了该行:

[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];

但我看不到如何使其适应 tableCell,除非我可以以某种方式在 细胞?我真的不知道。

如果有人对如何解决这个问题有任何其他想法,那就太好了。

谢谢,

马特

编辑:

问题现已解决,是一个非常愚蠢的错误,我忘记将我要移动到的 xib 上的视图链接到在我的头文件中以编程方式创建的视图

So I am trying to add in to my current Xcode project a table view which, whenever you click on a cell, whichever one it is, a new subview is added to the window. I will use global variables and the didSelectRowAtIndexPath to pass data on.

As it stands, I have my table view drawn on screen with the correct data inside. What I want to happen is when I click, a new subview is added but i cannot seem to get this to work.

I have tried adding the "addSubview" inside the didSelectRowAtIndexPath method itself and this did not work and I have tried declaring a separate method that loads a subview called 'loadDetails' then calling it with [self loadDetails] when a cell is selected but it wants an id after the call and I don't know what to pass in.

I have elsewhere in my project used the line:

[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];

But I can't see how to adapt this to the tableCell unless I could somehow add a new button over the cell? I really don't know.

If anybody has any other ideas of how to solve this problem, that would be great.

Thanks,

Matt

EDIT:

Problem is now solved, was a really stupid mistake, I forgot to link the view on the xib I was moving to, to the view created programmatically in my header file

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

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

发布评论

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

评论(1

墨落画卷 2024-12-07 13:44:06

尝试使用presentModalViewController来显示您的视图,然后从modalViewController中将其关闭:

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

DetailView *detailView = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];

[self presentModalViewController:detailView animated:YES];

}

try using presentModalViewController to show your view, and then dismiss it from the modalViewController:

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

DetailView *detailView = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];

[self presentModalViewController:detailView animated:YES];

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