2011-03-14 81 views
0

我使用uitextview從通訊錄中搜索聯繫人詳細信息。即像uisearchbar一樣搜索聯繫人詳細信息,而在uitextview中進行文本編輯更改。如何使用iphone中的uitextview從地址簿中搜索聯繫人?

this is the image

我使用的UITextView如果我點擊「A」,從通訊錄中的聯繫人列表將在表視圖中顯示

請給我解決

+1

你可能會得到更多的答案,如果你表明你寫的代碼,並詳細說明什麼是/不管用。 – Greg 2011-03-14 16:44:38

+0

@GregInYEG:這裏我添加了圖片請確認 – Sri 2011-03-14 17:07:49

+0

首先,點擊iPhone(或任何沒有鼠標的設備)是不可能的。其次,在Mac上製作屏幕截圖時,使用⇧⌘4,然後按空格鍵。第三,[Three20](https://github.com/facebook/three20)有一個消息編輯器類。你可以看看它的源代碼。 – 2011-03-14 17:08:17

回答

0

最後我得到了解決簡單的編碼這裏是

// viewDidLoad中

NSMutableArray *personArray = [[NSMutableArray alloc] init]; 
    ABRecordRef personRef; 
    for (int i = 0; i < CFArrayGetCount(allPeople); i++) 
    { 
    personRef = (ABRecordID*)CFArrayGetValueAtIndex(allPeople, i); 
    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(personRef)); 
    @try 
    { 
     if (ABRecordCopyValue(person, kABPersonBirthdayProperty)) 
      [personArray addObject: (id)personRef]; 
    } 
    @catch (NSException * e) 
    { 
    } 
    @finally 
    { 
    } 
    NSString *FirstName = [[[NSString stringWithString:(NSString *)ABRecordCopyValue(personRef, kABPersonFirstNameProperty)]stringByAppendingString:@" "]stringByAppendingString:(NSString *)ABRecordCopyValue(personRef, kABPersonLastNameProperty)]; 
    [arr addObject:FirstName]; 
} 
[arr3 addObjectsFromArray:arr]; 
    } 

// textviewdidchange

[arr3 removeAllObjects]; 
    NSInteger counter = 0; 
    for(NSString *name in arr) 
    { 
    NSRange r = [name rangeOfString:txtView.text options:NSCaseInsensitiveSearch]; 
    if(r.location != NSNotFound) 
    { 
     [arr3 addObject:name]; 
    } 
    counter++; 
} 
[table reloadData]; 

感謝您的幫助

相關問題