我的应用程序出现奇怪的问题
环境:Xcode 7.1.1
我写得很快,有随机崩溃,我有以下功能:
private func _generateTitleButton(frame: CGRect,title:String)->UIButton{
//Font Property:
let buttonFont = UIFont(name: "Roboto-Regular", size: 13)!;
let button = UIButton(frame:frame);
//crash point
button.setTitle(title, forState: .Normal);
button.setTitleColor(UIColor.whiteColor(), forState: .Normal);
button.titleLabel!.font = buttonFont;
button.contentMode = UIViewContentMode.Top;
button.addTarget(self, action: "titleButtonClicked:", forControlEvents: .TouchDown);
return button;
}
当实际字符串是枚举原始值时,我将召唤函数:
private enum titleButtonsText : String{
case NOTES = "NOTES";
case PEOPLE = "PEOPLE";
case INFO = "INFO";
}
功能用途:
self.infoButton = self._generateTitleButton(CGRect(origin: CGPoint(x: baseX, y: originY), size: buttonSize),title:titleButtonsText.INFO.rawValue);
在
_generateTitleButton
中,由于某种原因,title:String
是下一个字符串:保留\ 0release \ 0autorelease \ 0retainCount \臭氧应用\ 0hash \ 0superclass \ 0description \ 0debugDescription \ 0scrollViewDidScroll:\ 0scrollViewDidZoom:\ 0scrollViewWillBeginDragging:\ 0scrollViewWillEndDragging:withVelocity:targetContentOffset:\ 0scrollViewDidEndDragging:willDecelerate:\ 0scrollViewWillBeginDecelerating:\ 0scrollViewDidEndDecelerating:\ 0scrollViewDidEndScrollingAnimation:\ 0viewForZoomingInScrollView: \ 0scrollViewWillBeginZooming:withView:\ 0scrollViewDidEndZooming:withView:atScale:\ 0scrollViewShouldScrollToTop:\ 0scrollViewDidScrollToTop:\ 0_performScrollTest:withIterations:rowsToScroll:inComponent:\ 0tableView:numberOfRowsInSection:For0ViewIn \:InRowInSection:For0TableViewCell:InView:\ 0tableViewIndex: \ 0tableView:canEditRowAtIndexPath:\ 0tableView:canMoveRowAtIndexPath:\ 0sectionIndexTitlesForTableView:\ 0tableView:sectionForSectionIndexTitle:atIndex:\ 0tableView:commitEditingStyle:forRowAtIndexPath:\ 0tableView:moveRowAtIndexPath: toIndexPath:\ 0setSoundsEnabled:\ 0reload \ 0reloadDataForColumn
在崩溃点打印
self
:self = 0x0000000000000010 {
UIKit.UIView = {
UIKit.UIResponder = {
ObjectiveC.NSObject = {}
}
}
backButton = <read memory from 0x178 failed (0 of 8 bytes read)>
infoButton = <read memory from 0x180 failed (0 of 8 bytes read)>
peopleButton = <read memory from 0x188 failed (0 of 8 bytes read)>
notesButton = <read memory from 0x190 failed (0 of 8 bytes read)>
_border = <read memory from 0x198 failed (0 of 8 bytes read)>
title = <read memory from 0x1a0 failed (0 of 8 bytes read)>
saveButton = <read memory from 0x1a8 failed (0 of 8 bytes read)>
deleteButton = <read memory from 0x1b0 failed (0 of 8 bytes read)>
titleLabel = <read memory from 0x1b8 failed (0 of 8 bytes read)>
}
p.s该课程是单例
static var instance = CalendarMeetingViewTitle()
我最近所做的唯一更改是在应用程序中添加了带有解析功能的推送通知支持,并将按钮目标更改为另一种方法,该方法在过去几个月中一直有效
有任何想法吗?
谢谢!
最佳答案
我找到了解决方案,由于某种原因,它与单例有关。
static var instance = CalendarMeetingViewTitle()
至
private static var _instance : CalendarMeetingViewTitle?
static var instance :CalendarMeetingViewTitle{
if _instance == nil{
_instance = CalendarMeetingViewTitle();
}
return _instance!;
}
解决问题
关于ios - 使用String和UIButton的iOS快速随机崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33869029/