我无法显示此代码中的值.plz提供了显示mutabledictionay的代码和
- (void)viewDidLoad{
[super viewDidLoad];
mdict =[[NSMutableDictionary alloc]init];
[mdict setValue:@"abc" forKey:@"def"];
[mdict release];
}
-(void)display{
CFShow(mdict);
}
答案 0 :(得分:2)
使用
怎么样?-(void)display{
NSLog(@"%@",mdict);
}
将您的方法更改为:
- (void)viewDidLoad{
[super viewDidLoad];
mdict =[[NSMutableDictionary alloc]init];
[mdict setValue:@"abc" forKey:@"def"];
//if you want to display use following statement
[self display];
// [mdict release];//you should not release it here.
}
注意:在viewDidLoad
您正在使用[mdict release];
mdict将被释放!!!
这不应该在viewDidLoad
中,将该陈述放在dealloc
。
答案 1 :(得分:0)
首先您需要创建NSMutableDictionary
公开(在.h文件中声明),因为您在外部使用它并在dealloc
方法中释放其实例
- (void)viewDidLoad{
[super viewDidLoad];
self.mdict =[[NSMutableDictionary alloc]init];
[self.mdict setValue:@"abc" forKey:@"def"];
[self display];
}
-(void)display
{
NSLog(@"%@",[self.mdict objectForKey:@"def"]);
}
并在-(void)dealloc
方法