我有一个表视图,可变数组指针itemList保存其单元格的对象.我分配并初始化可变数组,
itemList = [[NSMutableArray alloc] init];
并将对象添加到数组中并加载表视图.
现在我需要释放整个数组并再次分配以保存要在表视图中显示的新对象数组.这就是我在做的事情
if(self.itemList!= nil){[self.itemList removeAllObjects]; [self.itemList release];
}
self.itemList = [[NSMutableArray alloc] init];
然后将对象添加到数组中以在表视图中显示.
我正在调用[tableview reloadData];
表格加载正确,但在此之后发生三到四次我的应用程序崩溃
现在,1.当我在分配后调用保留计数时,它显示2 y?2.我的应用程序崩溃一段时间后出现错误"iphone Program received signal:"0".警告:check_safe_call:无法恢复当前帧"
我怀疑itemList没有被正确释放.
有人可以指导我吗?
我在xcode项目的资源中有一个带有Array类型的根的plist文件.在按钮上单击我需要访问此plist并查找plist是否已包含特定项目,如果没有将新项目(NSString)写入plist.
我这样做如下,
NSMutableArray *array = nil;
NSDictionary *dictionary = nil;
path = [[NSBundle mainBundle] pathForResource:@"MyPlistName" ofType:@"plist"];
array = [[NSMutableArray alloc] initWithContentsOfFile:path];
dictionary = [self.dictionary objectForKey:@"tag"];
if(![array containsObject:dictionary])
{
[array addObject:dictionary];
if(![array writeToFile:path atomically:YES])
{
NSLog(@".plist writing was unsucessfull");
}
}
Run Code Online (Sandbox Code Playgroud)
这对我在模拟器上有效,但是当我在设备上运行时,writeToFile:atomically方法似乎总是返回NO.
我甚至尝试过使用NSArchiver,即使这似乎也没有将NO作为返回值
谁能说出我做错了什么..
问候,
Syed Yusuf