我到处寻找,希望有人能给我指明正确的方向。
我只想在每次用户选择不同的记录时运行一个方法。
更大的画面(万一有另一种方式)是,当用户选择记录(单次点击)时,将把人的电话号码放入分段的控件中。
我试过:
发布于 2013-01-01 13:50:47
拾荒者是一个。“复合视图”,它实际上包含一个桌面视图、2个按钮和一个搜索字段(IIRC)。
答:
你运气不好,这个组件不适合你的,但当然你做了一些黑客:
- (void)viewDidLoad {
//you get the internal tableview
id views = [self findSubviewsOfKind:NSClassFromString(@"ABPeoplePickerTableView") withTag:NSNotFound inView:sef.peoplePickerView];
id view = [views count] ? [views objectAtIndex:0] : nil;
//subscribe to the notification
if([view respondsToSelector:@selector(selectedRow)]) {
[[NSNotificationCenter defaultCenter] addObserverForName:NSTableViewSelectionDidChangeNotification object:view queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[self peoplePickerSelectedRecordChanged:self.peoplePickerView];
}];
}
}
- (NSArray *)findSubviewsOfKind:(Class)kind withTag:(NSInteger)tag inView:(NSView*)v {
NSMutableArray *array = [NSMutableArray array];
if(kind==nil || [v isKindOfClass:kind]) {
if(tag==NSNotFound || v.tag==tag) {
[array addObject:v];
}
}
for (id subview in v.subviews) {
NSArray *vChild = [self findSubviewsOfKind:kind withTag:tag inView:subview];
[array addObjectsFromArray:vChild];
}
return array;
}
- (IBAction)peoplePickerSelectedRecordChanged:(id)sender {
NSLog(@"%@", [sender selectedRecords]);
} 发布于 2014-05-30 17:37:21
ABPeoplePickerView为您所需的内容提供通知。查看类引用的末尾附近。
@implementation someController
@synthesize picker; //your ABPeoplePickerView
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
// or some other method that gets called early on
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(notificate:)
name:ABPeoplePickerNameSelectionDidChangeNotification
object:picker];
}
- (void) notificate: (NSNotification*) notification {
ABPerson *person = picker.selectedRecords.firstObject;
NSLog(@"NOTIFIED %@"), person.name);
// name is a property of ABPerson I added in a category
// do what you will
}如果你取消窗口,别忘了移除观察者。
https://stackoverflow.com/questions/14109207
复制相似问题