actionSheet:clickedButtonAtIndexデリゲートメソッドでUIActionSheet
を作成しています。応答時間が長いUIActionSheet
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
if(buttonIndex == 1){
[self.myFirstView removeFromSuperview];
if (!self.mySecondView) {
[[NSBundle mainBundle] loadNibNamed:@"MySecondView" owner:self options:nil];
}
[self.mySecondView setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication].keyWindow addSubview: self.mySecondView];
UIActionSheet * action = [[UIActionSheet alloc]initWithTitle:@""
delegate:self
cancelButtonTitle: nil
destructiveButtonTitle: deleteContacts
otherButtonTitles: cancel, nil];
action.tag = 102;
[action showInView:self.view];
[action release];
}
私はこのUIActionSheet
のクリックイベントを上記と全く同じ方法で処理します。
if(actionSheet.tag == 102){
if(buttonIndex == 0){
if([[NSBundle mainBundle] loadNibNamed:@"MyThirdView" owner:self options:nil]) {
[self.myThirdView setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication].keyWindow addSubview:self.myThirdView];
}
[self.mySecondView removeFromSuperview];
[self.doneButton.target performSelector:self.doneButton.action withObject:self.doneButton.target];
[self performSelector:@selector(RemoveView) withObject:self afterDelay:3.0];
}
}
私が直面しています問題は、UIActionSheet
が応答する時間がかかりすぎるということです。 UIActionSheet
ボタンをクリックすると、フリーズ状態の2〜3秒前に、myThirdView
が読み込まれます。私はUIActionSheet
ボタンのクリックイベントメソッドで最初に行うように、この場合の応答の遅延はmyThirdView
をロードすることになっています。残りのコードは、myThirdViewをロードするコードの後にのみ実行されます。しかし、コードの最初の行でさえ遅れて実行されているようです。 提案がありますか?
それは' [self.viewアクションshowInView]を動作しますか? – Felix
それは動作します。しかし、アクションシートの応答速度に大きな変化はありません。 –
私は正しい答えはザードとアンドリュージマーの答えを組み合わせるべきだと思います。バックグラウンドスレッドで実行されるべきコードは、次のコード行です。 '[self.doneButton.target performSelector:self.doneButton.action withObject:self.doneButton];'。 'RemoveView'メソッドを含む残りのコードは、メインスレッド上で実行されていなければなりません。ボタンタッチアクションをシミュレートするためのガブリエルに特別な言及。 –