gpt4 book ai didi

iOS 快速、随机崩溃 String 和 UIButton

转载 作者:行者123 更新时间:2023-11-30 13:54:08 24 4
gpt4 key购买 nike

我的应用遇到奇怪的问题

环境: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 是下一个字符串:

retain\0release\0autorelease\0retainCount\0zone\0hash\0superclass\0description\0debugDescription\0scrollViewDidScroll:\0scrollViewDidZoom:\0scrollViewWillBeginDragging:\0scrollViewWillEndDragging:withVelocity:targetContentOffset:\0scrollViewDidEndDragging:willDecelerate:\0scrollViewWillBegin正在减速:\0scrollViewDidEnd减速:\0scrollViewDidEndScrollingAnimation:\0viewForZoomingInScrollView:\0scrollViewWillBeginZooming:withView:\0scrollViewDidEndZooming:withView:atScale:\0scrollViewShouldScrollToTop:\0scrollViewDidScrollToTop:\0_performScrollTest:withIterations:rowsToScroll:inComponent:\0tableView:numberOfRowsInSection:\0tableView:cellForRowAtIndexPath:\0numberOfSectionsInTableView:\0tableView:titleForHeaderInSection :\0tableView:titleForFooterInSection:\0tableView:canEditRowAtIndexPath:\0tableView:canMoveRowAtIndexPath:\0sectionIndexTitlesForTableView:\0tableView:sectionForSectionIndexTitle:atIndex:\0tableView:commitEditingStyle:forRowAtIndexPath:\0tableView:moveRowAtIndexPath:toIndexPath:\0setSoundsEnabled:\0reload\0reloadData对于列

在崩溃点打印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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33869029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com