【发布时间】:2014-03-08 10:38:26
【问题描述】:
我正在尝试从 https://github.com/nicklockwood/CountryPicker 添加 UiPickerView 类 我想在我的 viewController 中使用故事板,但是尽管 pickerView 显示了国家,但委托方法永远不会被调用。 这是我所做的: 我导入了 CountryPicker 文件夹和 Flags 文件夹,在故事板控制器中我添加了一个 UiPickerView 并将其分配给 CountryPicker 类。 ViewController.h 和 .m 文件与示例完全相同。 我找不到我缺少的东西。 我也尝试初始化对象并从我的 ViewController.m 文件中调用 setSelectedCountry 方法,但它也没有做任何事情。 ViewController.h
#import <UIKit/UIKit.h>
#import "CountryPicker.h"
@interface ViewController : UIViewController <CountryPickerDelegate>
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CountryPicker *picker = [[CountryPicker alloc] init];
[picker.delegate self];
[picker setSelectedCountryCode:@"US" animated:YES];
}
- (void)countryPicker:(__unused CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code
{
NSLog(@"country: %@",name);
}
@end
【问题讨论】:
-
故事板上是否已经绘制了选择器?您在
viewDidLoad中分配的那个没有被添加为子视图? -
是的,它已经使用自定义类 (CountryPicker) 绘制在情节提要上
标签: ios uipickerview