2012-06-19 23 views
0

我試圖創建一個名稱自動完成的搜索欄,在圖像中看起來像這樣。IOS搜索標籤名稱完成氣泡

autocomplete text bubble

有沒有人有一個想法,我怎麼可能能夠實現這一目標?

+0

您是僅僅詢問編程方面還是關於圖形?如果只涉及編程,請參閱我的下面的答案。 – pasawaya

回答

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文件中訪問,因爲如果不這樣做,則無法在cellForRowAtIndexPath:方法中訪問它。

要實現自動補全,請遵循Ray Wenderlich的教程here關於自定義自動補全值。然後使用這些人的名字作爲自定義值。