В моем проекте тестирования я планирую иметь несколько видов выбора. Для этих видов выбора будут UIToolbars и пользовательские UIBarButtons. Я попытался создать метод класса, чтобы мне не пришлось повторять коды, но кажется, что кнопка не отображается.Пользовательский UIBarButtonItem для UIToolbar
Picker Совершено button.h
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (test)
+ (UIBarButtonItem*)barButtonItemWithTint:(UIColor*)color andTitle:(NSString*)itemTitle andTarget:(id)theTarget andSelector:(SEL)selector;
@end
Picker Совершено Button.m
#import "PickerDoneButton.h"
@implementation UIBarButtonItem (test)
+ (UIBarButtonItem*)barButtonItemWithTint:(UIColor*)color andTitle:(NSString*)itemTitle andTarget:(id)theTarget andSelector:(SEL)selector
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tintColor = color;
button.backgroundColor = [UIColor yellowColor];
[button addTarget:theTarget action:selector forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithCustomView:button];
return doneButton;
}
@end
И использовать этот метод класса на мой взгляд Controller.m (я опуская взгляд сборщика методы, которые поступают после viewDidLoad)
#import "ViewController.h"
#import "PickerDoneButton.h"
@interface ViewController()
@property (strong, nonatomic) NSArray *numberofPeople;
@property (strong, nonatomic) UIPickerView *countPeople;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.countPeople = [[UIPickerView alloc] init];
self.countPeople.dataSource = self;
self.countPeople.delegate = self;
self.numberofPeople = @[@"1",@"2",@"3"];
UIToolbar *countPeopleToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,0,50)];
countPeopleToolbar.barStyle = UIBarStyleBlackOpaque;
// Call the UIBarButtonItem from PickerDoneButton.h
countPeopleToolbar.items = @[[UIBarButtonItem barButtonItemWithTint:[UIColor redColor] andTitle:@"Done" andTarget:self andSelector:@selector(doneClicked)]];
[self pickerView:self.countPeople didSelectRow:0 inComponent:0];
}
Я правильно использую метод класса?
Не могу поверить, что я пропустил это ... Спасибо за помощь – OHHO