【发布时间】:2013-08-12 06:09:05
【问题描述】:
我有一个 plist,基本上是 8000 个用户名的列表。我将它加载到一个 NSDictionary 中,然后是一个排序键数组(因为我得到它时列表没有排序),然后循环加载到一个 NSComboBox 中。
这可行,但可能需要几秒钟来填充组合框。
这是我的代码:
// in my .h
IBOutlet NSComboBox *comboUserList; // which is connected to a combo box in my .xib
// in my .m
// userInfoPlist is an NSString path to the file
NSDictionary *userList = [NSDictionary dictionaryWithContentsOfFile:userInfoPlist];
// sort user info into an array
NSArray* sortedKeys = [userList keysSortedByValueUsingSelector:@selector(caseInsensitiveCompare:)];
// then populate the combo box from userList in the order specified by sortedKeys
for ( NSString *usersKey in sortedKeys) {
[comboUserList addItemWithObjectValue:[userList objectForKey:usersKey]];
}
所以这是可行的,但是对于 8000 个奇数条目,填充组合框需要一些明显的时间(在 2011 年的 MACBook Air 上只需一两秒,但仍然很明显)。有没有更快的方法来使用 NSDictionary 或 NSArray 作为数据源,而不是在 for 循环中执行?
【问题讨论】:
标签: objective-c xcode macos