IOS搜索标签名称完成泡泡

时间:2012-06-19 17:14:39

标签: ios user-interface

我正在尝试创建一个名称自动完成的搜索栏,在图片中看起来像这样。

autocomplete text bubble

有谁知道我怎么能够实现这个目标?

2 个答案:

答案 0 :(得分:2)

查看开源库TTMessageController中的TTMessageRecipientFieldThree20。这正是你想要的:

TTMessageController example

答案 1 :(得分:0)

首先,您需要一个包含联系人姓名的数组:

//Add Address Book framework    

#import <AddressBook/AddressBook.h>

--------------------

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *allPeople = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);

NSMutableArray *firstNames = [NSMutableArray alloc] init];

for(NSUInteger personIndex = 0; personIndex <= [allPeople count]; personIndex++){

    ABRecordRef person = (__bridge ABRecordRef)[allPeople objectAtIndex: incrementer];

    firstNameString = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

    [firstNames addObject: firstNameString];
}

所以firstNames数组现在包含了所有人的数组;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

    if (cell == nil) 
{
        cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(your, values, go, here) reuseIdentifier:@"MyIdentifier"];
    }

    cell.text = [firstNames objectAtIndex: indexPath.row];

}

到目前为止,您有一个包含所有名字的tableview。确保在协议UITableViewDataSourceUITableViewDelegate中实施其他必需的方法。另外,请确保在头文件中声明firstNames数组属性,以确保它在.m文件中可以访问,因为如果不这样做,则无法在{{1}中访问它方法。

要实现自动完成功能,请按照Ray Wenderlich的教程here了解自定义自动完成值。然后使用人们的名字数组作为自定义值。