我有一個UIViewController。我使用navigationItem的rightBarButtonItem作爲「重新加載按鈕」。當按下重新加載按鈕時,我使用leftBarButtonItem在應用程序正在處理要重新加載的數據時顯示活動指示器。一切都很好,直到這裏。
下面是一些代碼:更改navigationItem的barButtonItem
- (void)initSpinner {
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityButton = [[UIBarButtonItem alloc] initWithCustomView: activityIndicator];
self.navigationItem.leftBarButtonItem = activityButton;
}
- (void)spinBegin {
[activityIndicator startAnimating];
}
- (void)spinEnd {
[activityIndicator stopAnimating];
}
- (void)viewDidLoad {
[self initSpinner];
[super viewDidLoad];
//more stuff going on here....
}
-(void) loadView{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshFeeds:)];
}
現在我被要求改變邏輯位。
rightBarButtonItem保持不變。 leftBarButtonItem仍然在那裏顯示活動指標,但是當沒有處理時它應該顯示另一個按鈕,當按下時它將顯示一個新的視圖(對於某些信息)。
所以我做了這些變化:
- (void)initSpinner {
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityButton = [[UIBarButtonItem alloc] initWithCustomView: activityIndicator];
}
- (void)spinBegin {
self.navigationItem.leftBarButtonItem = activityButton;
[activityIndicator startAnimating];
}
- (void)spinEnd {
[activityIndicator stopAnimating];
self.navigationItem.leftBarButtonItem =infoBarButton; //= [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshFeeds:)] autorelease];
}
-(void) loadView{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshFeeds:)];
if (infoBarButton == nil){
UIImage *buttonImage = [UIImage imageNamed:@"info.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0, 0.0, 25, 25);
// Initialize the UIBarButtonItem
infoBarButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
// Set the Target and Action for aButton
[aButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
}
self.navigationItem.leftBarButtonItem = infoBarButton;
}
雖然它似乎是工作(Info按鈕是存在的,當我按下「刷新」的activityIndicator取代其位置,直到處理完成),我得到了下面的調試器控制檯:
__NSAutoreleaseNoPool(): Object 0x15ef30 of class UINavigationItem autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1abd90 of class UIBarButtonItem autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1acb20 of class UIButton autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x15ef30 of class UINavigationItem autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1ad030 of class UIActivityIndicatorView autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1ad030 of class UIActivityIndicatorView autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1a8c40 of class UINavigationButton autoreleased with no pool in place - just leaking
Object 0x941c of class NSCFString autoreleased with no pool in place - just leaking
//MORE similar messages following...
我在做什麼錯?我希望有人可以幫助...
在此先感謝。
您使用後臺線程來處理你的數據? – Hisenberg 2011-05-24 14:39:16