私はいくつかの計算を行う簡単なアプリを作っています。これらの計算の一部はかなり複雑なので、結果を得るにはしばらく時間がかかることがあります。ユーザーが値を入力できるように私はUITableView
を使用しています。次に、 "計算"ボタンをクリックした後、簡単にUIView
をUIActivityIndicatorView
にして、画面中央に置きます。そして、私はバックグラウンドで計算方法を呼び出します。いくつかのコード:[self.tableView reloadData]のEXC_BAD_ACCESS
self.activityIndicatorView = [[UIView alloc]initWithFrame:CGRectMake(320/2 - 50, (480 - 64)/2 - 50, 100, 100)];
self.activityIndicatorView.layer.cornerRadius = 10.0f;
self.activityIndicatorView.backgroundColor = [UIColor colorWithRed:0. green:0. blue:0. alpha:0.7];
UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
actInd.frame = CGRectMake((100 - actInd.frame.size.width)/2, (100 - actInd.frame.size.height)/2, actInd.frame.size.width, actInd.frame.size.height);
[actInd startAnimating];
[self.activityIndicatorView addSubview:actInd];
[self.activityIndicatorView bringSubviewToFront:actInd];
[self.view addSubview:self.activityIndicatorView];
[self.view bringSubviewToFront:self.activityIndicatorView];
[self performSelectorInBackground:@selector(calculateAllThatShizzle) withObject:nil];
ご覧のとおり、かなり簡単です。
2012-03-23 11:06:32.418 MyApp[869:5c07] bool _WebTryThreadLock(bool), 0x6adb270: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1 WebThreadLock
2 -[UITextRangeImpl isEmpty]
3 -[UITextRange(UITextSelectionAdditions) _isCaret]
4 -[UITextSelectionView setCaretBlinks:]
5 -[UIKeyboardImpl setCaretBlinks:]
6 -[UIKeyboardImpl setDelegate:force:]
7 -[UIKeyboardImpl setDelegate:]
8 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:]
9 -[UIResponder _finishResignFirstResponder]
10 -[UIResponder resignFirstResponder]
11 -[UITextField resignFirstResponder]
12 -[UITableView reloadData]
13 -[ChildViewController calculateAllThatShizzle]
14 -[NSThread main]
15 __NSThread__main__
16 _pthread_start
17 thread_start
だから、問題はからキーボードで何かをしようとしていることである:キーボードがまだ表示されている場合、それはログ内のそれと-(void)calculateAllThatShizzle
方法で[self.tableView reloadData]
になるときしかし、それは(EXC_BAD_ACCESS
)のクラッシュバックグラウンドスレッド。私は細胞をループして[cell.rightTextField resignFirstResponder]
と呼ぶことを試みましたが、それは助けになりません。私もそれを試してみた
-(void)reloadTableViewData {
[self.tableView reloadData];
}
-(void)calculateAllThatShizzle {
//some code omitted - code that uses UIKit
if ([dob timeIntervalSinceDate:calcDate]>0) {
[errorButton setTitle:@"Calculation Date must be more than Date of Birth" forState:UIControlStateNormal];
errorButton.hidden = NO;
[self.activityIndicatorView removeFromSuperview];
self.activityIndicatorView = nil;
return;
}
[self performSelectorOnMainThread:@selector(reloadTableViewData) withObject:nil waitUntilDone:NO];
}
しかし、それは助けにもなりません。私は使用していますELCTextfieldCell
助けていただければ幸いです。
ありがとうございました
P.S. reloadDataのEXC_BAD_ACCESS
に関するその他の質問を確認しましたが、問題があるとは限りません。
P.P.S.また、私はちょうどメインスレッドで計算を実行することができますが、その後、GUIが応答しなくなり、活動の指標には
カスタムセルを使用しましたか? – hchouhan02
@schそれは '[self.tableView reloadData];' – Novarg
@ HChouhan02 yes、 'ELCTextfieldCell'の代わりに' - (void)calculateAllThatShizzle'メソッドにあります。ラベルとtextFieldを提供します。 [here here](http://www.cocoacontrols.com/platforms/ios/controls/elctextfieldcell) – Novarg