gpt4 book ai didi

cocoa - NSComboBox列表默认滚动到底部

转载 作者:行者123 更新时间:2023-12-03 17:14:21 24 4
gpt4 key购买 nike

我有一个完全标准的 NSComboBox。它设置了一个数据源来为其提供内容,效果很好。问题是,当用户单击查看列表时,它开始一直滚动到列表底部而不是顶部。我发现

- (void)scrollItemAtIndexToTop:(NSInteger)index

并尝试过放置

[comboBox scrollItemAtIndexToTop:0];

在不同的地方,但它没有做任何事情。这比其他任何事情都更烦人,我无法弄清楚。

提前致谢。

编辑:来自数据源的代码:

- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
return [[engineTypesArrayController arrangedObjects] count];
}

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index
{
return [[[engineTypesArrayController arrangedObjects] objectAtIndex:index] valueForKey:@"title"];
}


- (NSString *)comboBoxCell:(NSComboBoxCell *)aComboBoxCell completedString:(NSString *)uncompletedString
{
NSArray *matchingObjects = [[engineTypesArrayController arrangedObjects] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(logTenCustomizationProperty_title BEGINSWITH[c] %@)", uncompletedString]];

if (matchingObjects && ([matchingObjects count] > 0))
{
return [[matchingObjects objectAtIndex:0] valueForKey:@"title"];
}
else
{
return nil;
}
}

comboBox:indexOfItemWithStringValue 未实现。

最佳答案

添加此委托(delegate)方法有效:

#pragma mark - ComboBox delegate
- (void)comboBoxWillPopUp:(NSNotification *)notification
{
NSComboBox *comboBox = [notification object];

[comboBox scrollItemAtIndexToVisible:0];
}

关于cocoa - NSComboBox列表默认滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11478069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com