我想从UITableViewCell(Xib)导航到UIViewController,但是当我尝试使用当前的Value of type 'TableViewCell' has no member 'present
时
因此,如果有人熟悉可以帮助我进行导航的功能,请帮助我:)。
谢谢您的时间
答案 0 :(得分:2)
UITableViewCell无法显示视图控制器。请将viewController存储到tableview单元中的变量。并用它来呈现。
或使用didSelectRowAt
委托函数并使用self进行演示(或如果事件通过单元格中的按钮触发,则编写自定义单元格委托)
答案 1 :(得分:2)
使您的ViewController
符合UITableViewDelegate
协议,然后在ViewController
代码中使用委托方法:func tableView(UITableView, didSelectRowAt: IndexPath)
,并在此方法内执行/呈现segue或任何其他类型导航。
import UIKit
class ViewController: UIViewController, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(UITableView, didSelectRowAt: IndexPath) {
// navigation logic here
}
}
答案 2 :(得分:1)
在自定义 <div id = "buttonID" style = "display :block;">
<p:selectOneMenu id="selectformName" value="#{tformBean.formName}" >
<f:selectItem itemLabel="Select Category.. " itemValue=" " />
<f:selectItems value="#{tformServices.getDistinctTformName()}" />
<p:ajax update="formNameid formid" partialSubmit="true"/>
<!-- <p:ajax event ="change" listener = "tformServices.submitA(tformBean.formID)" update="formNameid" partialSubmit="true"/> -->
</p:selectOneMenu>
<br></br>
<p:commandButton value="ADD DATA TO CATEGORY" process= " formNameid" style="margin-right:20px;" styleClass="ui-priority-primary" onclick ="hideshowAddCat();">
</p:commandButton>
<div class="ui-g-12 ui-lg-4" style="background:#f2f2f2;margin-top:15px;">
<div class="card card-w-title">
<label for="formid">FORM_ID<i class="fa fa-asterisk" style="color: red;"></i></label>
<p:panelGrid columns="1" layout="grid" styleClass="ui-panelgrid-blank form-group">
<p:inputText id="formid" placeholder="FORM_ID" value="#{tformBean.formID}" required = "true">
</p:inputText>
</p:panelGrid>
</div>
</div>
<div class="ui-g-12 ui-lg-4" style="background:#f2f2f2;margin-top:15px;">
<div class="card card-w-title">
<label for="formNameid">FORM_NAME<i class="fa fa-asterisk" style="color: red;"></i></label>
<p:panelGrid columns="1" layout="grid" styleClass="ui-panelgrid-blank form-group">
<p:inputText id="formNameid" placeholder="FORM_NAME" value="#{tformBean.formName}" required = "true">
</p:inputText>
</p:panelGrid>
</div>
中使用 closure
处理这种情况。
在您的自定义UITableViewCell
中创建一个UITableViewCell
,并在handler
内点击button
时调用它,即
cell
现在,在创建class CustomCell: UITableViewCell {
var handler: (()->())?
@IBAction func onTapButton(_ sender: UIButton) {
handler?()
}
}
时在handler
中设置cellForRowAt
,即
cell