スレッドバックグラウンドの更新が行われている間にUIViewをウィンドウに追加してから、デリゲートメソッドを使用してビューを削除します。すべてが意図どおりに行われていますが、hideActivityViewerが呼び出されてから数秒間表示されます。それが問題なのかどうかは分かりませんが、アプリはUITabBarControllerを使用しています。スーパービューからUIViewが削除されるのが遅い
更新メソッドは別のクラスにありましたが、デバッグの目的で現在AppDelegate.mにあります。私が言ったように、すべてが機能します。更新が完了すると、 "Foo"がログに書き込まれますが、ビューは数秒間持続します。どんな助けもありがとう。余分なコードは省略されています:
AppDelegate.h
@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
UIView *activityView;
id _delegate;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
- (void)showActivityViewer;
- (void)updateComplete;
- (void)updateRemoteDataThreadedWithDelegate:(id)aDelegate;
- (id)delegate;
- (void)setDelegate:(id)new_delegate;
@end
AppDelegate.m
- (void)updateRemoteDataThreadedWithDelegate:(id)aDelegate {
[self setDelegate:aDelegate];
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(updateRemoteDataWithDelegate:) object:aDelegate];
[queue addOperation:operation];
[operation release];
}
- (void)updateRemoteDataWithDelegate:(id)aDelegate {
[self setDelegate:aDelegate];
...do stuff...
if ([_delegate respondsToSelector:@selector(updateComplete)]) {
[_delegate updateComplete];
} else {
[NSException raise:NSInternalInconsistencyException format:@"Delegate doesn't respond to updateComplete"];
}
}
-(void)showActivityViewer {
[activityView release];
activityView = [[UIView alloc] initWithFrame: CGRectMake(window.bounds.size.width-50, 60, 50, 50)];
...formatting...
[window addSubview: activityView];
[activityView release];
}
-(void)hideActivityViewer {
[activityView removeFromSuperview];
activityView = nil;
NSLog(@"Foo");
}
- (id)delegate {
return _delegate;
}
- (void)setDelegate:(id)new_delegate {
_delegate = new_delegate;
}
ありがとうございました。私は2日間それを浪費する前にここで尋ねたはずだと思います。見つけた=] – SalsaShark