我已經創建了子類UIToolbar,以便更輕鬆地實現下一步的Safari瀏覽器,之前完成了某些操作。 這一切工作正常,當我直接添加它(即不是子類),但現在我是,它崩潰每次我點擊其中一個按鈕與 -[keyboardToolBar hideKeyboard:]: unrecognized selector sent to instance
這是我第一次嘗試子類的東西,所以我沒有當然,如果我做錯了一些事情。子類化時崩潰UIToolbar
代碼的子類
@interface keyboardToolBar : UIToolbar {
UIToolbar *keyboard;
UIBarItem *previous;
UIBarItem *next;
UIBarItem *done;
}
@property (nonatomic, retain) UIToolbar *keyboard;
@property (nonatomic, retain) UIBarItem *previous;
@property (nonatomic, retain) UIBarItem *next;
@property (nonatomic, retain) UIBarItem *done;
-(void)previousField;
-(void)nextField;
-(void)hideKeyboard;
@end
#import "keyboardToolBar.h"
@implementation keyboardToolBar
@synthesize keyboard, previous, done, next;
-(UIToolbar*)initWithFrame:(CGRect)frame{
//Create a new toolbar
keyboard = [[UIToolbar alloc]initWithFrame:frame];
//Create all the buttons and point them to methods
UIBarButtonItem *previousButton = [[UIBarButtonItem alloc] initWithTitle:@"Previous"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(previousField:)];
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(nextField:)];
UIBarButtonItem *filler = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(hideKeyboard:)];
//Set the width of both of the buttons to make it look pritty
previousButton.width = 70.0f;
nextButton.width = 70.0f;
self.previous = previousButton;
self.next = nextButton;
self.done = doneButton;
//Add the buttons to the toolbar
[keyboard setItems:[[[NSArray alloc] initWithObjects:self.previous, self.next, filler, self.done, nil] autorelease]];
//Release the buttons
[previous release];
[next release];
[filler release];
[done release];
//return the shiny new toolbar
return keyboard;
}
-(void)previousField{
}
-(void)nextField{
}
-(void)hideKeyboard{
NSLog(@"hello");
}
@end
並使用UIToolbar *keyboard = [[keyboardToolBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)];
我已經試過所有我能想到的,但仍然得到同樣的錯誤調用。我敢肯定,我只是不保留一些地方指向按鈕來錯了地方,但任何幫助將長久地感謝 感謝 斯達克
大壩吧,新的它會很簡單。謝謝 – Darc