gpt4 book ai didi

Cocoa:ABPeoplePickerView - 如何在单击一个人时触发方法?

转载 作者:行者123 更新时间:2023-12-03 17:23:29 24 4
gpt4 key购买 nike

我到处寻找,希望有人能给我指出正确的方向。

我只想在每次用户选择不同的记录时运行一个方法。

更大的图景(如果有替代方法)是,当用户选择记录(单击)时,该人的电话号码将被放入分段控件中。

我已经尝试过:

  1. 要将操作连接到按钮,我通常打开助理编辑器,然后右键单击拖动到 .h 文件。但是当我使用 abpeoplepickerview 执行此操作时,我只获得 Outlet 连接类型?

最佳答案

人员选择器是一个 . “复合 View ”实际上由一个表格 View 、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]);
}

关于Cocoa:ABPeoplePickerView - 如何在单击一个人时触发方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14109207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com