This is the whole code of that function to show the str in text view. Memo1 is the textview outlet.
ERROR happens calling this function.
-(void)showMeg:(NSString *)str
{
dispatch_sync(dispatch_get_main_queue(), ^{
[[[Memo1 textStorage] mutableString]appendString:[NSString
stringWithFormat:@"%@", str]];
[Memo1 scrollRangeToVisible:NSMakeRange(Memo1.string.length, 0)];//auto scroll down
});
}
Someone suggested me change dispatch_sync to dispatch_async or close the dispatch_sync with a dispatch_async like following.
Then the error, EXC_BAD..., disappeared but I found the order of the strings showed on textview is wrong few times, not often.
For example, I'd like to show 0x01, 0x02, 0x03. But it shows 0x01, 0x03, 0x02.
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_sync(dispatch_get_main_queue(), ^{
[[[Memo1 textStorage] mutableString]appendString:[NSString stringWithFormat:@"%@", str]];
[Memo1 scrollRangeToVisible:NSMakeRange(Memo1.string.length, 0)];//auto scroll down
});
});
Post
Replies
Boosts
Views
Activity
I found the bug. This error solved.
An array only has one object but I call the 2nd index of that array, so it caused the error.
Sorry, the second section was copied the same code.
The following is what I actually called.