我的ViewModel带有ObservableCollection
private ObservableCollection<ObjectView> _elementList;
public ObservableCollection<ObjectView> ElementList
{
get { return _elementList; }
set { _elementList = value; RaisePropertyChanged("ElementList"); }
}
从TableView通过异步线程绑定它被称为ReloadData(即在我的TableView上有一个endlessscroll)。我注意到了这个错误(有时候,并非总是让它崩溃我的应用程序):
Feb 28 10:14:25 iPhone-di-Luigi JRUITouch[4518] <Warning>: CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0 QuartzCore 0x31ce00a5 <redacted> + 268
1 QuartzCore 0x31cdff59 <redacted> + 224
2 QuartzCore 0x31ce05bb <redacted> + 30
3 QuartzCore 0x31ce1f6b <redacted> + 158
4 QuartzCore 0x31ce546d <redacted> + 40
5 UIKit 0x3219a2c5 <redacted> + 48
6 UIKit 0x321d0c65 <redacted> + 460
7 UIKit 0x321d0a45 <redacted> + 68
8 CoreFoundation 0x2f8240f3 <redacted> + 90
9 CoreFoundation 0x2f824003 <redacted> + 198
10 UIKit 0x3213a825 <redacted> + 628
11 LSUITouch 0x001a24ec wrapper_managed_to_native_MonoTouch_ObjCRuntime_Messaging_void_objc_msgSend_intptr_intptr + 100
12 LSUITouch 0x0017b948 MonoTouch_UIKit_UITableView_ReloadData + 52
13 LSUITouch 0x00a210d4 Cirrious_MvvmCross_Binding_Touch_Views_MvxBaseTableViewSource_ReloadTableData + 176
14 LSUITouch 0x00a24cf0 Cirrious_MvvmCross_Binding_Touch_Views_MvxTableViewSource_CollectionChangedOnCollectionChanged_object_System_Collections_Specialized_NotifyCollectionChangedEventArgs + 248
有人知道如何修复?
答案 0 :(得分:1)
通过Stuart建议解决了问题。
从外部线程更新UI会很危险......你可能会有一些意想不到的影响。然后每次我在我的ObservableCollection上添加元素时,我都以这种方式在主线程上调用了这个更新:
private void AddElementsOnMainThread(AdvertObjectView item){
MvxMainThreadDispatcher.Instance.RequestMainThreadAction((Action)delegate(){
ElementList.Add(item);
});
}
以这种方式,我没有更多的警告和我的UI线程,它免受意外惊喜!