0
我正在嘗試在多個viewcontroller的tableviews中出現一個標題視圖。我不知道我應該設置xib文件所有者類。我正在嘗試這樣做,以便我可以在標題的操作上調用按鈕。我已經嘗試過UIViewController,並沒有運氣。任何幫助將不勝感激。給xib多個文件所有者
我正在嘗試在多個viewcontroller的tableviews中出現一個標題視圖。我不知道我應該設置xib文件所有者類。我正在嘗試這樣做,以便我可以在標題的操作上調用按鈕。我已經嘗試過UIViewController,並沒有運氣。任何幫助將不勝感激。給xib多個文件所有者
如果您爲視圖創建專用控制器類,那麼最好的(在我看來)。你可以加載和添加加載的ViewController,如:
let cmVC = ColorMenuVC(nibName: "ColorMenu", bundle: Bundle.main, textProperty: _textProperty!)
//font menu initialization & settings
cmVC.modalPresentationStyle = UIModalPresentationStyle.popover
//popover settings
let popover = cmVC.popoverPresentationController
popover?.delegate = self
popover?.barButtonItem = sender
popover?.permittedArrowDirections = UIPopoverArrowDirection.any
//presenting
present(cmVC, animated: true, completion: nil)
這個例子爲Popovers,但我希望這會有所幫助。該ColorMenuVC是擴展的UIViewController,但這裏是原班如何初始化:
https://developer.apple.com/reference/uikit/uiviewcontroller/1621487-nibname
創建一個超所有相關視圖控制器子類,把相關行動/在那裏網點和所有者類設置爲超類。類似於目標C版本在這裏https://stackoverflow.com/questions/9368635/using-idprotocol-for-files-owner-in-interface-builder – CupawnTae
我試着做一個類是一個uiviewcontroller和設置其他VC的該類,而不是他們的普通UIViewController和文件所有者作爲該類,但它仍然不會連接 –
你應該發佈你的非工作代碼,並解釋你如何連接它 - 這會讓人更容易幫助你 – CupawnTae