我有以下内容ViewController:
ViewController
class PageContentViewController: UIViewController { var pageIndex: Int }
我如何pageIndex从另一个ViewController 访问?
pageIndex
我需要访问pageIndex此功能:
func pageViewController(pageViewController: UIPageViewController!, viewControllerBeforeViewController viewController: UIViewController!) -> UIViewController! { //var index: Int //index = ? NSUInteger index = ((PageContentViewController*) viewController).pageIndex; // in Swift? if ((index == 0) || (index == NSNotFound)) { return nil; } index--; return [self viewControllerAtIndex:index]; // in Swift? }
默认情况下,swift中的所有内容都是公开的,因此,如果您声明以下内容:
class SomeViewController: UIViewController { var someVariable: SomeType = someValue init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } }
只要拥有它的实例,就可以访问它:
var myCustomViewController: SomeViewController = SomeViewController(nibName: nil, bundle: nil) var getThatValue = myCustomViewController.someVariable