以编程方式在UITableViewCell中显示带有按钮的视图控制器(Swift) [英] Presenting a View Controller with a button in a UITableViewCell programmatically (Swift)
问题描述
我试图在用户点击表格视图中的表格视图单元格时将其带到新的视图控制器。更具体地说,当用户点击人员用户名时,应该将他们带到该用户档案。用户名是表视图单元格,配置文件是新视图控制器。我认为这样做的方法是使用.presentViewController(vc,animated:true,completion:nil)然而,当我这样做时,它说myCell没有名为.presentViewController的成员
I am trying to make it where when a user clicks on a table view cell in my table view it takes them to a new view controller. More specifically, when a user clicks on a persons username it should take them to that users profile. the username being the table view cell and the profile being the new view controller. I thought the way to do this was to use the ".presentViewController(vc, animated: true, completion: nil) however when i do this it says "myCell does not have a member named .presentViewController"
如果有人能帮我解决这个问题呢非常感谢
If anyone could help me solve this problem it'd be greatly appreciated
推荐答案
presentViewController:animated:completion
是 UIViewController的实例方法
而不是 UIView
或其子类。您可以尝试这样:
The presentViewController:animated:completion
is an instance method of the UIViewController
not UIView
or a subclass of. You can try this:
self.window?.rootViewController.presentViewController(specificViewController, animated: true, completion: nil)
但是,我建议你应该使用 presentViewController:animated:
方法来自 UIViewController
。可以在 UIViewController
之间实现回调机制和单元格
。
However, I suggest that you should use the presentViewController:animated:completion:
method from UIViewController
. A callback mechanism can be achieved between the UIViewController
and the cell
.
如下所示:在UI表格视图单元格内单击获取按钮
这篇关于以编程方式在UITableViewCell中显示带有按钮的视图控制器(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!