I use xamarin studio to debug the uitableview page, there is one UITextview in UITableviewCell, I will load data from web service and set text for UITextview, But when I load data in several times, It will crash in set text for UITextview and the crash log is this:
Incident Identifier: 4144836D-E8DC-434C-8552-FA63A686D6D4
CrashReporter Key: a35f5169df95f13a4431b55a8b6e41aa6576396e
Hardware Model: iPad3,1
Process: MobileLaw [238]
Path: /var/mobile/Applications/6FDEF7FD-D46D-4F81-9D41-D920C2B98ECF/MobileLaw.app/MobileLaw
Identifier: MobileLaw
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2013-09-10 09:18:02.395 +0800
OS Version: iPhone OS 5.1.1 (9B206)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x91b6732e
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x30a5832c __pthread_kill + 8
1 libsystem_c.dylib 0x32fe9208 pthread_kill + 48
2 libsystem_c.dylib 0x32fe2298 abort + 88
3 MobileLaw 0x013b03fa 0x1000 + 20640762
4 MobileLaw 0x0136a832 0x1000 + 20355122
5 libsystem_c.dylib 0x32ff37e6 _sigtramp + 42
6 UIKit 0x30d68b82 -[UITextView webViewDidChange:] + 166
7 Foundation 0x370074f8 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 12
8 CoreFoundation 0x37dc3540 ___CFXNotificationPost_block_invoke_0 + 64
9 CoreFoundation 0x37d4f090 _CFXNotificationPost + 1400
10 Foundation 0x36f7b3e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60
11 WebCore 0x3119b47a WebThreadPostNotification + 62
12 WebKit 0x3760959e WebEditorClient::respondToChangedContents() + 30
13 WebCore 0x31365ea6 WebCore::Editor::setTextAsChildOfElement(WTF::String const&, WebCore::Element*) + 738
14 WebKit 0x37603d00 -[WebFrame(WebPrivate) setText:asChildOfElement:] + 188
15 UIKit 0x30d693ac -[UITextView setText:] + 300
16 MobileLaw 0x001cd708 0x1000 + 1885960
17 MobileLaw 0x00f4f57c 0x1000 + 16049532
18 MobileLaw 0x00f4c73c 0x1000 + 16037692
19 MobileLaw 0x00f4bc98 0x1000 + 16034968
20 MobileLaw 0x008e5094 0x1000 + 9322644
21 MobileLaw 0x0136c02c 0x1000 + 20361260
22 MobileLaw 0x013d7858 0x1000 + 20801624
23 MobileLaw 0x0133954c 0x1000 + 20153676
24 UIKit 0x30c30ef4 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 540
25 UIKit 0x30c2ffd2 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1070
26 UIKit 0x30c2f75c -[UITableView layoutSubviews] + 200
27 UIKit 0x30bd3f30 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 176
28 CoreFoundation 0x37d561f4 -[NSObject performSelector:withObject:] + 36
29 QuartzCore 0x331eba9e -[CALayer layoutSublayers] + 210
30 QuartzCore 0x331eb6b6 CA::Layer::layout_if_needed(CA::Transaction*) + 210
31 QuartzCore 0x331ef83c CA::Context::commit_transaction(CA::Transaction*) + 220
32 QuartzCore 0x331ef578 CA::Transaction::commit() + 308
33 QuartzCore 0x331e74b2 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 50
34 CoreFoundation 0x37dcbb14 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
35 CoreFoundation 0x37dc9d50 __CFRunLoopDoObservers + 252
36 CoreFoundation 0x37dca0aa __CFRunLoopRun + 754
37 CoreFoundation 0x37d4d49e CFRunLoopRunSpecific + 294
38 CoreFoundation 0x37d4d366 CFRunLoopRunInMode + 98
39 GraphicsServices 0x36230432 GSEventRunModal + 130
40 UIKit 0x30bfecce UIApplicationMain + 1074
41 MobileLaw 0x001d394c 0x1000 + 1911116
42 MobileLaw 0x00dbcf54 0x1000 + 14401364
43 MobileLaw 0x008e5094 0x1000 + 9322644
44 MobileLaw 0x0136c02c 0x1000 + 20361260
45 MobileLaw 0x013d7858 0x1000 + 20801624
46 MobileLaw 0x013da578 0x1000 + 20813176
47 MobileLaw 0x013ddea4 0x1000 + 20827812
48 MobileLaw 0x0138272c 0x1000 + 20453164
49 MobileLaw 0x014291e8 0x1000 + 21135848
50 MobileLaw 0x0001f888 0x1000 + 125064
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x30a483a8 kevent + 24
1 libdispatch.dylib 0x34722f04 _dispatch_mgr_invoke + 708
2 libdispatch.dylib 0x34722c22 _dispatch_mgr_thread + 30
Thread 2:
0 libsystem_kernel.dylib 0x30a48054 semaphore_wait_trap + 8
1 MobileLaw 0x0137d4d8 0x1000 + 20432088
2 MobileLaw 0x0141bcf4 0x1000 + 21081332
3 MobileLaw 0x01406ffe 0x1000 + 20996094
4 MobileLaw 0x013705e2 0x1000 + 20379106
5 MobileLaw 0x013b55f0 0x1000 + 20661744
6 libsystem_c.dylib 0x32faa72e _pthread_start + 314
7 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 3 name: WebThread
Thread 3:
0 libsystem_kernel.dylib 0x30a580d8 __psynch_mutexwait + 24
1 libsystem_c.dylib 0x32f9e674 pthread_mutex_lock + 376
2 WebCore 0x311324e8 _ZL17_WebTryThreadLockb + 208
3 WebCore 0x311327ec _ZL14WebRunLoopLockP19__CFRunLoopObservermPv + 24
4 CoreFoundation 0x37dcbb14 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
5 CoreFoundation 0x37dc9d50 __CFRunLoopDoObservers + 252
6 CoreFoundation 0x37dca16a __CFRunLoopRun + 946
7 CoreFoundation 0x37d4d49e CFRunLoopRunSpecific + 294
8 CoreFoundation 0x37d4d366 CFRunLoopRunInMode + 98
9 WebCore 0x311d5c9c _ZL12RunWebThreadPv + 396
10 libsystem_c.dylib 0x32faa72e _pthread_start + 314
11 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 4:
0 libsystem_kernel.dylib 0x30a58628 __semwait_signal + 24
1 libsystem_c.dylib 0x32faeb1a nanosleep + 138
2 MobileLaw 0x0136fb18 0x1000 + 20376344
3 MobileLaw 0x014007ae 0x1000 + 20969390
4 MobileLaw 0x01406ffe 0x1000 + 20996094
5 MobileLaw 0x013705e2 0x1000 + 20379106
6 MobileLaw 0x013b55f0 0x1000 + 20661744
7 libsystem_c.dylib 0x32faa72e _pthread_start + 314
8 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 5:
0 libsystem_kernel.dylib 0x30a58068 __psynch_cvwait + 24
1 libsystem_c.dylib 0x32faaa46 _pthread_cond_wait + 634
2 libsystem_c.dylib 0x32fb1574 pthread_cond_timedwait + 40
3 MobileLaw 0x01415a00 0x1000 + 21056000
4 MobileLaw 0x0136e480 0x1000 + 20370560
5 MobileLaw 0x01405fde 0x1000 + 20991966
6 MobileLaw 0x008a8210 0x1000 + 9073168
7 MobileLaw 0x008a855c 0x1000 + 9074012
8 MobileLaw 0x008a76dc 0x1000 + 9070300
9 MobileLaw 0x008a4168 0x1000 + 9056616
10 MobileLaw 0x008e5094 0x1000 + 9322644
11 MobileLaw 0x0136c02c 0x1000 + 20361260
12 MobileLaw 0x013d7858 0x1000 + 20801624
13 MobileLaw 0x013d795e 0x1000 + 20801886
14 MobileLaw 0x01407014 0x1000 + 20996116
15 MobileLaw 0x013705e2 0x1000 + 20379106
16 MobileLaw 0x013b55f0 0x1000 + 20661744
17 libsystem_c.dylib 0x32faa72e _pthread_start + 314
18 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 6:
0 libsystem_kernel.dylib 0x30a58570 __select + 20
1 libsystem_kernel.dylib 0x30a49d2c select + 44
2 MobileLaw 0x01379722 0x1000 + 20416290
3 MobileLaw 0x01401290 0x1000 + 20972176
4 MobileLaw 0x01406ffe 0x1000 + 20996094
5 MobileLaw 0x013705e2 0x1000 + 20379106
6 MobileLaw 0x013b55f0 0x1000 + 20661744
7 libsystem_c.dylib 0x32faa72e _pthread_start + 314
8 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 7:
0 libsystem_kernel.dylib 0x30a4806c semaphore_timedwait_trap + 8
1 MobileLaw 0x0137d47a 0x1000 + 20431994
2 MobileLaw 0x01402158 0x1000 + 20975960
3 MobileLaw 0x01406ffe 0x1000 + 20996094
4 MobileLaw 0x013705e2 0x1000 + 20379106
5 MobileLaw 0x013b55f0 0x1000 + 20661744
6 libsystem_c.dylib 0x32faa72e _pthread_start + 314
7 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 8:
0 libsystem_kernel.dylib 0x30a4806c semaphore_timedwait_trap + 8
1 MobileLaw 0x0137d47a 0x1000 + 20431994
2 MobileLaw 0x01402158 0x1000 + 20975960
3 MobileLaw 0x01406ffe 0x1000 + 20996094
4 MobileLaw 0x013705e2 0x1000 + 20379106
5 MobileLaw 0x013b55f0 0x1000 + 20661744
6 libsystem_c.dylib 0x32faa72e _pthread_start + 314
7 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 9:
0 libsystem_kernel.dylib 0x30a4806c semaphore_timedwait_trap + 8
1 MobileLaw 0x0137d47a 0x1000 + 20431994
2 MobileLaw 0x01402158 0x1000 + 20975960
3 MobileLaw 0x01406ffe 0x1000 + 20996094
4 MobileLaw 0x013705e2 0x1000 + 20379106
5 MobileLaw 0x013b55f0 0x1000 + 20661744
6 libsystem_c.dylib 0x32faa72e _pthread_start + 314
7 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 10 name: com.apple.NSURLConnectionLoader
Thread 10:
0 libsystem_kernel.dylib 0x30a48004 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x30a481fa mach_msg + 50
2 CoreFoundation 0x37dcb3ec __CFRunLoopServiceMachPort + 120
3 CoreFoundation 0x37dca124 __CFRunLoopRun + 876
4 CoreFoundation 0x37d4d49e CFRunLoopRunSpecific + 294
5 CoreFoundation 0x37d4d366 CFRunLoopRunInMode + 98
6 Foundation 0x36f88bb2 +[NSURLConnection(Loader) _resourceLoadLoop:] + 302
7 Foundation 0x36f88a7a -[NSThread main] + 66
8 Foundation 0x3701c58a __NSThread__main__ + 1042
9 libsystem_c.dylib 0x32faa72e _pthread_start + 314
10 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 11 name: WebCore: CFNetwork Loader
Thread 11:
0 libsystem_kernel.dylib 0x30a48004 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x30a481fa mach_msg + 50
2 CoreFoundation 0x37dcb3ec __CFRunLoopServiceMachPort + 120
3 CoreFoundation 0x37dca124 __CFRunLoopRun + 876
4 CoreFoundation 0x37d4d49e CFRunLoopRunSpecific + 294
5 CoreFoundation 0x37d4d366 CFRunLoopRunInMode + 98
6 WebCore 0x311ff0d2 _ZN7WebCoreL15runLoaderThreadEPv + 122
7 libsystem_c.dylib 0x32faa72e _pthread_start + 314
8 libsystem_c.dylib 0x32faa5e8 thread_start + 0
Thread 12:
0 libsystem_kernel.dylib 0x30a58cd4 __workq_kernreturn + 8
1 libsystem_c.dylib 0x32fa4f36 _pthread_wqthread + 610
2 libsystem_c.dylib 0x32fa4cc8 start_wqthread + 0
Thread 13:
0 libsystem_kernel.dylib 0x30a58cd4 __workq_kernreturn + 8
1 libsystem_c.dylib 0x32fa4f36 _pthread_wqthread + 610
2 libsystem_c.dylib 0x32fa4cc8 start_wqthread + 0
Thread 14:
0 libsystem_kernel.dylib 0x30a58cd4 __workq_kernreturn + 8
1 libsystem_c.dylib 0x32fa4f36 _pthread_wqthread + 610
2 libsystem_c.dylib 0x32fa4cc8 start_wqthread + 0
Thread 0 crashed with ARM Thread State:
r0: 0x00000000 r1: 0x00000000 r2: 0x00000001 r3: 0x00000000
r4: 0x00000006 r5: 0x3e924d98 r6: 0x01455f20 r7: 0x2fdfc644
r8: 0x00000000 r9: 0x00000000 r10: 0x01455f46 r11: 0x0357f6c0
ip: 0x00000148 sp: 0x2fdfc638 lr: 0x32fe920f pc: 0x30a5832c
cpsr: 0x00000010
Binary Images:
0x1000 - 0x14d0fff +MobileLaw armv7 <a8f2805092f63491948848f582058ecf> /var/mobile/Applications/6FDEF7FD-D46D-4F81-9D41-D920C2B98ECF/MobileLaw.app/MobileLaw
0x2dd5000 - 0x2dd5fff +MobileSubstrate.dylib armv6 <a059eb894e623ec09d63294c525ff7a2> /Library/MobileSubstrate/MobileSubstrate.dylib
0x2f11000 - 0x2f12fff +SubstrateLoader.dylib armv6 <eec9b813adfd3bdf86702ae8bbf0f404> /Library/Frameworks/CydiaSubstrate.framework/Libraries/SubstrateLoader.dylib
0x2fe15000 - 0x2fe36fff dyld armv7 <77eddfd654df393ba9c95ff01715fd08> /usr/lib/dyld
In C#
, @Dharmbir answer translate to
InvokeOnMainThread (()=> {
textView.Text = "your text";
});
I think you are doing this in background thread. So thats totally wrong according to apple because apple don't allow to touch UIKit in background thread. So you need to set text like this
[self performSelectorOnMainThread:@selector(setTextOnTextView) withObject:nil waitUntilDone:NO];
- (void)setTextOnTextView
{
// ---------- set your text here -------
}
Here is my code : the button setTitle would't crash, it will crash on setText.and the other question is when I debug the program, It will crash on the second load data.When I run the program without debug, It will crash little on the second load data,after several times load data it will crash
string values = ValueList[curCellNumber] == null ? "" : ValueList[curCellNumber].ToString();
UITableViewCell cell = tableView.DequeueReusableCell(cellIdentity);
UITextView textView = cell.ViewWithTag(10001) as UITextView;
UIButton btnSelects=cell.ViewWithTag(10002) as UIButton;
if(btnSelects != null){
btnSelects.SetTitle(curCellNumber,UIControlState.Normal);
}
this.InvokeOnMainThread(() => {
if (textView != null) {
textView.Text = values;
textView.Delegate = new TextViewDelegate(DataTableName, FieldList[curCellNumber], TID);
}
});
Whatever you change on UI, it has to be done within UI thread. In other words, If you execute some code in some other thread, and want to make changes to UI, you should put it into
this.InvokeOnMainThread(() => { });
Also, scope of textView is problematic. Monotouch garbage collector is kind of strange in this situations and in some cases it will collect it before you would expect. Declare it as global or class property (or property of your custom table cell). In your code, there is a rush: Will mainthread access textView before GetCell (or whatever method where textView is declared) ends and GC collects textView?
User contributions licensed under CC BY-SA 3.0