1

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

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

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

我试过了:

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

2 回答 2

0

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
}

如果您关闭窗口,请不要忘记删除观察者。

于 2014-05-30T17:37:21.997 回答
0

人员选择器是一个 . “复合视图”实际上由一个表格视图、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]);
} 
于 2013-01-01T13:50:47.707 回答