我想暗示功能就像當我點擊搜索字段時,我需要顯示搜索字段下的條件列表。基於我需要搜索的標準。我如何將這個列表添加到搜索字段中。 在此先感謝。如何動態添加列表到搜索字段?
2
A
回答
0
對於在SearchField
動態出現的列表中,你必須拖動和下降的searchfield
outlet
您window
第一則searchfield
委託連接fileowners
一旦做到這一點,然後教學貫徹下面的代碼: -
在這下面代碼它包含一個元素數組,如果在搜索字段中輸入任何長度大於3的單詞,則它將根據array
中的匹配單詞顯示結果列表。
-(void)controlTextDidChange:(NSNotification *)obj
{
NSArray *[email protected][@"item1",@"item2",@"item3",@"item4",@"test1",@"test2",@"test3",@"test4",@"test5"];
NSString *searchString = [self.searchField stringValue];
NSMenu *menu= [[NSMenu alloc] initWithTitle: @"results"];
if (searchString.length>3)
{
NSArray *filteredArray = [filterArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF like %@", [searchString stringByAppendingString:@"*"]]];
for (NSString *addMenuItem in filteredArray)
{
[menu addItemWithTitle: addMenuItem action: @selector(someAction:) keyEquivalent: @""];
}
NSEvent *event = [NSEvent otherEventWithType: NSApplicationDefined
location: [self.searchField frame].origin
modifierFlags: 0
timestamp: 0
windowNumber: [[self.searchField window] windowNumber]
context: [[self.searchField window] graphicsContext]
subtype: NSAppKitDefined
data1: 0
data2: 0];
[NSMenu popUpContextMenu: [menu autorelease] withEvent: event forView: self.searchField];
}
}
-(void)someAction:(id)sender
{
//if you want to perform some action write here
}
相關問題
- 1. 如何將動態搜索參數添加到Sharepoint搜索?
- 2. blackberry在列表字段中添加搜索字段
- 3. 動態添加索引到列表
- 4. 將搜索框添加到ASP.Net動態數據列表頁面
- 5. 動態字段搜索
- 6. Playframework:動態搜索字段
- 7. 如何動態添加輸入字段到表單
- 8. 如何動態添加輸入字段到表單?
- 9. 將推薦列表動態添加到輸入字段
- 10. 動態搜索python列表
- 11. 添加鑰匙扣到搜索列表?
- 12. 搜索並添加到數組列表
- 13. 如何添加動態字段?
- 14. 如何動態添加輸入字段?
- 15. 如何動態添加模型字段?
- 16. 如何動態添加輸入字段
- 17. 如何動態添加其他字段
- 18. 中添加動態文本字段添加到HTML表格
- 19. 如何在搜索表單中添加動態選擇菜單
- 20. 隱藏動態添加的列/字段
- 21. 黑莓 - 如何添加字段到列表字段?
- 22. 在動態列表視圖中搜索和添加項目
- 23. 添加結果到搜索字段的自動推薦
- 24. VBA問題:將搜索文本字段添加到現有搜索表單
- 25. 搜索並添加到按字母順序排列的列表
- 26. 將列動態添加到列列表
- 27. SQL PHP可搜索表格字段添加到新數據庫
- 28. 添加表單輸入字段動態
- 29. Ionic 2動態添加表格字段
- 30. 將索引添加到mysql動態列
我已經更新了代碼。請看看它 –