[英]Creating segue from programmatically created table view
我是 iOS 開發新手,在完成了一些基礎教程和初級書籍后,我查看了 iOS 編程的示例。 之后我找到了這個。
https://github.com/uacaps/PageMenu
我下載了示例,但遇到問題。 我正在使用 PageMenuDemoTabbar ( https://github.com/uacaps/PageMenu/tree/master/Demos/Demo%204/PageMenuDemoTabbar ) 示例。 我想在用戶單擊 tableviewcell 時添加 segues。 但問題就在這里。 因為以編程方式創建的 tableviews,我無法從故事板添加 segues。
我怎么能做到這一點?
感謝幫助。
如果你想從 Storyboard 轉到另一個視圖控制器,只需將 StoryboardID 添加到這個視圖控制器(就像我有 RootViewController 和 StoryboardID RootVC ):
然后為要傳遞給視圖控制器的數據創建公共屬性(即@property (nonatomic, strong) NSDictionary *propertyYouSet
)。 然后在您的-tableView:didSelectItemAtIndexPath:
UITableView 委托方法中添加以下代碼:
YourViewController *yourViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"YourViewControllerStoryboardID"];
yourViewController.propertyYouSet = @{ 'someKey': 'someValueYouWantToPass' };
[self.navigationController pushViewController:yourViewController animated:YES];
這樣你仍然可以使用 Storyboard 視圖控制器而無需轉場。
糟糕,剛剛注意到swift
標簽。 所以這是 Swift 中的相同代碼:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("yourViewControllerStoryboardID") as! UIViewController
vc.setYourProperty(someDictionaryHere) // I'm not so sure about this, I'm new in Swift too :)
self.presentViewController(vc, animated: true, completion: nil)
}
然后在您的視圖控制器中覆蓋此方法:
init(coder aDecoder: NSCoder!)
{
super.init(coder: aDecoder)
}
(因為在 Swift 中-initWithCoder:
是必需的 :) )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.