I have an application that works fine in the simulator, however, when I run it on the device, the application runs slowly and crashes from time to time. This problem occurs when you click on a tableview cell and switch to a new view. When you click on a cell, a second or two delays occur, then the new view will slowly move forward. This is also the place where it will sometimes break.
The application worked fine on the device until recently, adding some changes to the code in which I think the problem lies. I added the entire viewDidLoad file containing the suspect code (specified in the code).
Another thing that I noticed is that CPU usage in the debug navigator is about 130%, and the application runs in sim at the point where the problem occurs on the device.
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, 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 ie 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") }
source share