CoreAnimation未提交CATranaction NSComboBox

时间:2015-06-14 19:00:54

标签: xcode swift core-animation nscombobox catransaction

我正在使用以下函数中的一些数据填充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

0 个答案:

没有答案