Swift – 推送ViewController进入黑屏

Swift – 推送ViewController进入黑屏,第1张

概述所以我有一个包含tableView的View Controller.只要单击一个tableview单元格,就会推入另一个视图控制器.这个新的视图控制器有自己的xib.文件和 swift文件.我在新的viewcontroller中有一个mapview,但是当推入时新的视图控制器是黑色的.我该如何解决这个问题? TableView didSelectRowAtIndexPath方法: func tab 所以我有一个包含tableVIEw的VIEw Controller.只要单击一个tablevIEw单元格,就会推入另一个视图控制器.这个新的视图控制器有自己的xib.文件和 swift文件.我在新的vIEwcontroller中有一个mapvIEw,但是当推入时新的视图控制器是黑色的.我该如何解决这个问题?
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进入黑屏所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005123.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存