我正在添加一個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;
}
謝謝。我想我應該在這裏浪費兩天時間來問這裏。發現。 =] – SalsaShark 2011-02-02 22:49:12