tableVIEw dIDSelectRowAtIndexPath方法:
func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) { var cell = tableVIEw.cellForRowAtIndexPath(indexPath) as BusinesstableVIEwCell var business = self.results[indexPath.row] var mapVIEw = BusinessMapVIEwController() mapVIEw.business = business mapVIEw.mapVIEw = MKMapVIEw() self.navigationController?.pushVIEwController(mapVIEw,animated: true) println("\(business.name) SELECTED")}
新视图控制器:
import UIKitimport MapKitclass BusinessMapVIEwController: UIVIEwController {@IBOutlet weak var mapVIEw: MKMapVIEw!var business:Business!overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw. let location = CLLocationCoordinate2D( latitude: 37.774929,longitude: -122.419416 ) let span = MKCoordinateSpanMake(0.1,0.1) let region = MKCoordinateRegion(center: location,span: span) println(business.latitude) mapVIEw.setRegion(region,animated: true)}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated.}/*// MARK: - Navigation// In a storyboard-based application,you will often want to do a little preparation before navigationoverrIDe func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) { // Get the new vIEw controller using segue.destinationVIEwController. // Pass the selected object to the new vIEw controller.}*/
}
解决方法 如果您的新VIEwController有自己的swift文件,那么您可以在dIDSelectRowAtIndexPath方法中尝试这样的事情:let mapVIEw = self.storyboard?.instantiateVIEwControllerWithIDentifIEr("MapVIEwController") as BusinessMapVIEwController
之后你可以用这个推送到nextVIEwController:
self.navigationController?.pushVIEwController(mapVIEw,animated: true)
但不要忘记添加StoryBoard ID,否则会崩溃.
你的代码将是:
func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) {var cell = tableVIEw.cellForRowAtIndexPath(indexPath) as BusinesstableVIEwCellvar business = self.results[indexPath.row]let mapVIEw = self.storyboard?.instantiateVIEwControllerWithIDentifIEr("MapVIEwController") as BusinessMapVIEwControllermapVIEw.business = businessmapVIEw.mapVIEw = MKMapVIEw()self.navigationController?.pushVIEwController(mapVIEw,animated: true)println("\(business.name) SELECTED")}
可能这会对你有所帮助.
总结以上是内存溢出为你收集整理的Swift – 推送ViewController进入黑屏全部内容,希望文章能够帮你解决Swift – 推送ViewController进入黑屏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)