在我的 UIViewController 中,我想在工具栏中添加一个 UIBarButtonItem,但没有出现新的 Button。我究竟做错了什么?
- (void)doLogin:(NSString *)name password:(NSString *)password {
// 1.: start the Thread:
NSInvocationOperation *invOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(backgroundTaskLogin:) object:request];
[self.opQueue addOperation:invOperation];
}
- (void)backgroundTaskLogin:(NSString *)request2 {
// 2.: jump back in the Main Thread in show a cancel button in den toolbar:
[self performSelectorOnMainThread:@selector(showCancelButton) withObject:nil waitUntilDone:NO];
}
- (void)showCancelButton {
// 3.: add a new Cancel-Button in the Toolbar:
UIBarButtonItem *tempButtonCancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelLogin)];
NSMutableArray *myButtons = (NSMutableArray *)self.toolbarItems;
NSLog(@"Count buttons: %d", [self.toolbarItems count]); // DEBUGGER: 2
[myButtons addObject:tempButtonCancel];
[tempButtonCancel release];
NSLog(@"Count buttons: %d", [self.toolbarItems count]); // DEBUGGER: 3
// PROBLEM: I don't see the new Toolbar-Button :-(
}