Let me describe my problem first. I have a class which holds a NSMutableDictionary ivar. There is a thread that will add new pairs into this dictionary - at the moment of writing the application I m not able to have a full list of available keys. An up-to-date list of all this pairs have to be shown in the Table View. I ve prepared small proof of concept application where there is a Dictionary Controller created in the xib file, and its content is binded with the dictionary ivar. The problem is that Table View shows only initial set of the dictionary s content. After insertion it s not refreshed.
在我对概念应用的证明中。
#import <Foundation/Foundation.h>
@interface AppController : NSObject
@property (strong) NSMutableDictionary *dictionary;
- (NSString *)randomString;
- (IBAction)addRandomPair:(id)sender;
@end
执行档案内容:
#import "AppController.h"
@implementation AppController
@synthesize dictionary = _dictionary;
- (id)init {
self = [super init];
if (self) {
_dictionary = [[NSMutableDictionary alloc] init];
[_dictionary setValue:@"Aa" forKey:@"A"];
[_dictionary setValue:@"Bb" forKey:@"B"];
}
return self;
}
- (NSString *)randomString
{
NSMutableString *aString = [[NSMutableString alloc] init];
for (int i = 0; i < 3; i++) {
NSUInteger r = random() % ( z - a );
[aString appendString:[NSString stringWithFormat:@"%c", ( a +r)]];
}
return aString;
}
- (IBAction)addRandomPair:(id)sender
{
[self.dictionary setValue:[self randomString] forKey:[self randomString]];
NSLog([self.dictionary description]);
}
@end
临时主计长 内容受申请人主计长的约束,其示范关键路径被设定为“自订人”,表观点的栏目内容受持有模型关键路径的副行长的约束,因此具有关键和价值。 在概念应用的这种证据中,纽特加点添加了一个新的奶制品(addRandomPair: 行动)。
我与一名国家情报和安全局署长和阿雷拉主计长有着同样的问题,但我得以通过在掌握一阵列的类别(该类别中的名称数据)上添加各种方法来解决问题:
- (void)insertObject:(NSString *)object inDataAtIndex:(NSUInteger)index;
- (void)removeObjectFromDataAtIndex:(NSUInteger)index;
www.un.org/Depts/DGACM/index_spanish.htm 是否有可能在一名独裁者(主计长)的班级中增加一些其他方法,以了解新的插入情况? 或者,我的问题的解决可能更好?
Update
I ve found out that implementing following set of accessors makes Dictionary Controller notified about new item:
- (void)addDictionaryObject:(NSString *)object;
- (void)removeDictionaryObject:(NSString *)object;
www.un.org/Depts/DGACM/index_spanish.htm 问题是<代码>addDictionaryObject:。 仅有一条论点,字典需要addDictionaryObject:forKey:
。 任何想法?
Update 2
我看不出除使用人工变更通知以外的任何其他解决办法——此处为<代码>addRandomPair:。 方法如下:
- (IBAction)addRandomPair:(id)sender
{
[self willChangeValueForKey:@"dictionary"];
[self.dictionary setValue:[self randomString] forKey:[self randomString]];
[self didChangeValueForKey:@"dictionary"];
NSLog([self.dictionary description]);
}
它发挥了作用,但我仍是一个不确定的因素,因为词典本身不会改变,而是其内容。 <>strong> 采用人工变更通知的方法?