我正在尝试创建一个可以调用以轻松实现完成工具栏的类。
目前我这样称呼它,
-(void)textFieldDidBeginEditing:(UITextField *)textField{
DoneToolbar *tlbDone = [[DoneToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
[textField setInputAccessoryView:tlbDone];
}
这可以调出工具栏,但问题是“完成”按钮,
目前我正在尝试通过以下代码执行此操作,
#import "DoneToolbar.h"
@implementation DoneToolbar
@synthesize btnDone;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//Done Button
UIBarButtonItem *doneBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(btnDonePressed)];
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *barItemArr = [NSArray arrayWithObjects:flexible,doneBarButton, nil];
self.items = barItemArr;
[self.superview endEditing:YES];
}
return self;
}
- (void)btnDonePressed{
[self.superview endEditing:YES];
}
@end
我做错了什么?