iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS应用程序在Xcode模拟器中运行良好,但速度很慢并且在设备上崩溃大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个在模拟器中正常运行的应用程序,但是当我在设备上运行时,应用程序运行缓慢并偶尔崩溃.特别是在点击tableview单元格并转换到新视图时会出现此问题.当点击一个单元格有一两秒或两个延迟时,新视图将以缓慢的延迟方式推送.这也是偶尔崩溃的地方.

该应用程序在设备上正常运行,直到最近添加了一些代码更改,这是我认为问题所在.我添加了包含可疑代码的整个viewDidLoad bellow(在代码中指出).

我注意到的另一件事是调试导航器中的cpu使用率大约为130%,而应用程序在设备上发生问题时在sim中运行.

override func viewDidLoad() {
    super.viewDidLoad()

    // screen size for collection view cell
    screenSize = UIScreen.mainScreen().bounds
    screenWidth = screenSize.width
    screenHeight = screenSize.height

    dimView.alpha = 0
    openingHoursView.alpha = 0

    resDescriptionLabel.layer.borderColor = UIColor.blackColor().CGColor
    resDescriptionLabel.layer.borderWidth = 2
    resDescriptionLabel.layer.cornerRadius = 4

    //add logo to nav bar
    let navBarlogo: UIImageView = UIImageView(frame: CGRectMake(0,120,36))
    navBarlogo.image = UIImage(named: "logo")
    self.navigationItem.titleView = navBarlogo

    self.resImage.image = UIImage(named: "placeholder")
    if let checkedUrl = NSURL(String: "http://staging.api.cheapeat.com.au/restaurants/\(self.venuEID)/photo") {
        downloadImage(checkedUrl)
    }

    self.resName.text = " " + self.venuename + " "
    self.resAdd.text = " " + self.venueAdd + " "
    self.resPhone.text = "\(self.venuePH)"
    self.resPhonenumber.text = self.venuePH
    self.resWebText.text = "\(self.venueWeb)"

    ///////////////////// new code starts here //////////////

    var paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.alignment = NSTextAlignment.Justified
    paragraphStyle.lineBreakmode = NSLineBreakmode.byWordWrapping

    var attributedString = NSAttributedString(String: self.venueInfo,attributes: [
            NSParagraphStyleAttributename: paragraphStyle,NSBaselineOffsetAttributename: NSnumber(float: 0)

        ])

    self.resDescriptionLabel.attributedText = attributedString

    aboutVenueLabelWidthConsTraint.constant = screenWidth - 16

    resDescriptionLabel.edgeInsets.left = 10
    resDescriptionLabel.edgeInsets.top = 10
    resDescriptionLabel.edgeInsets.right = 10
    resDescriptionLabel.edgeInsets.bottom = 10

    resDescriptionLabel.layoutIfNeeded()

    BACkgroundImageHeightConsTraint.constant = resDescriptionLabel.bounds.height + 130

    // set content view height i.e. scrollable area
    // (dynamic height of label + combined height of all other content and conTraints)
    contentViewHeightConsTraint.constant = resDescriptionLabel.bounds.height + 790

    /////////////////// new code ends here ///////////////

    self.displaymap(self.venueLat,lng: self.venueLng)
    self.getArrayForCollection()
    self.getArrayValues()
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT,0),{ () -> Void in

        self.getDataForNextTable()
        })

    mon.text = timeFormatTing(openingHours,day: "Monday")
    tue.text = timeFormatTing(openingHours,day: "Tuesday")
    wed.text = timeFormatTing(openingHours,day: "Wednesday")
    thu.text = timeFormatTing(openingHours,day: "Thursday")
    fri.text = timeFormatTing(openingHours,day: "Friday")
    sat.text = timeFormatTing(openingHours,day: "Saturday")
    sun.text = timeFormatTing(openingHours,day: "Sunday")
}
@H_489_14@解决方法
我找到了罪魁祸首,事实证明它毕竟不在代码中.我在scrollView中设置了一些背景图像,分辨率很高(5000×5000).他们绝对是在咀嚼内存(在调试器中达到400mb左右).我调整了图像大小,问题解决了.

大佬总结

以上是大佬教程为你收集整理的iOS应用程序在Xcode模拟器中运行良好,但速度很慢并且在设备上崩溃全部内容,希望文章能够帮你解决iOS应用程序在Xcode模拟器中运行良好,但速度很慢并且在设备上崩溃所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。