gpt4 book ai didi

xcode - CoreAnimation 未提交 CATranaction NSComboBox

转载 作者:搜寻专家 更新时间:2023-10-31 23:03:13 27 4
gpt4 key购买 nike

我正在用下面函数中的一些数据填充 NSComboBox。在它被填充后,我尝试滚动浏览我收到 CATransaction 警告的项目。任何人都可以阐明为什么会发生这种情况以及我可以做些什么来解决它吗?我发现这可能与在主线程以外的线程上更改组合框的 UI 有关,但之后我就卡住了。

func getAllRecords()
{
CATransaction.begin()
let url = NSURL(string: "http://URL.php")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!)
{
(data, response, error) in
var d = NSString(data: data, encoding: NSUTF8StringEncoding)
var arr = d!.componentsSeparatedByString("<") // spliting the incoming string from "<" operator because before that operator is our required data and storing in array
var dataWeNeed:NSString = arr[0] as! NSString // arr[0] is the data before "<" operator and arr[1] is actually no use for us
if let data = NSJSONSerialization.JSONObjectWithData(dataWeNeed.dataUsingEncoding(NSUTF8StringEncoding)!, options: NSJSONReadingOptions.MutableContainers, error: nil) as? NSArray
{
for dd in data
{
var name : String = dd["Name"]! as! String
var email : String = dd["Email"]! as! String
//println("Name: \(name)")
//println("Email: \(email)")
self.userComboBox.addItemsWithObjectValues([name])
}
}
}
task.resume()
CATransaction.commit()
}

这是我从调试区域收到的警告。

2015-06-14 13:54:04.756 Green Time Clock[2150:738395] Unexpected        outstanding background CATransaction
CoreAnimation: warning, encountered thread with uncommitted CATransaction; created by:
0 QuartzCore 0x00007fff9ab4d6c2 _ZN2CA11Transaction4pushEv + 312
1 QuartzCore 0x00007fff9ab689a8 _ZN2CA11Transaction15ensure_implicitEv + 276
2 QuartzCore 0x00007fff9ab4d842 _ZN2CA11Transaction9set_valueEj12_CAValueTypePKv + 40
3 QuartzCore 0x00007fff9ab4f452 +[CATransaction setDisableActions:] + 38
4 AppKit 0x00007fff921a1b8c -[NSView(NSInternal) _updateLayerGeometryFromView] + 389
5 AppKit 0x00007fff921c7d09 -[NSView setFrameSize:] + 1129
6 AppKit 0x00007fff921c789a -[NSControl setFrameSize:] + 77
7 AppKit 0x00007fff922e3891 -[NSTableView setFrameSize:] + 256
8 AppKit 0x00007fff922e35f9 -[NSTableView _tileAndRedisplayAll] + 180
9 Green Time Clock 0x00000001000042d6 _TFFC16Green_Time_Clock14ViewController13getAllRecordsFS0_FT_T_U_FTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError__T_ + 2886
10 Green Time Clock 0x0000000100004463 _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 51
11 Green Time Clock 0x0000000100001e31 _TPA__TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 81
12 Green Time Clock 0x0000000100004493 _TTRXFo_iTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError___iT__XFo_oGSQS__oGSQS0__oGSQS1___dT__ + 35
13 Green Time Clock 0x00000001000044fa _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFdCb_dGSQS__dGSQS0__dGSQS1___dT__ + 90
14 CFNetwork 0x00007fff8c09cba2 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 157
15 Foundation 0x00007fff9a75f7e8 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7

最佳答案

不确定根本问题是什么,我在将字符串值更新为 NSTextView 对象时发现了警告,并使用以下代码解决了它。

只需确保更新过程在主线程中处理即可。

//链接:NSTextStorage limitation on size and frequency of updates

dispatch_block_t block = ^ {
NSAttributedString *attributeString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n", strLog]];

NSTextStorage* store = [_textViewOutputLog textStorage];
[store beginEditing];
[store appendAttributedString:attributeString];
[store endEditing];
[_textViewOutputLog scrollRangeToVisible:NSMakeRange([[_textViewOutputLog string] length], 0)];
};

if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}

关于xcode - CoreAnimation 未提交 CATranaction NSComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30833324/

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