[英]iPhone SDK: updating objects in an NSArray
I have an NSArray of (Product) objects that are created by parsing an XML response from a server. 我有一个(Array)对象的NSArray,这些对象是通过解析服务器的XML响应创建的。
In the object, it has images, and text, and ints, URLs. 在对象中,它具有图像和文本,以及整数和URL。 etc. 等等
There are 2 requests to the server 1: list of matching products from a search - small amount of detail 2: product details: the full details. 对服务器有2个请求1:从搜索中找到匹配产品的列表-少量详细信息2:产品详细信息:完整详细信息。
When the second request is parsed I am trying to update the existing object in the array. 当解析第二个请求时,我正在尝试更新数组中的现有对象。
- (void) setProduct:(Product *) _product atIndex: (int) index
{
[_product retain];
[productList replaceObjectAtIndex:index withObject:_product];
}
This doesn't seem to work as when I call update and table reloadData, the new values are not present. 这似乎不起作用,因为当我调用update和table reloadData时,新值不存在。
Should I remove the object in the array first? 我应该先删除数组中的对象吗?
replaceObjectAtIndex: is a method of NSMutableArray. replaceObjectAtIndex:是NSMutableArray的方法。 So you would need to do make your productLists a NSMutableArray to use it. 因此,您需要将productLists设置为NSMutableArray才能使用它。
-(void)updateprevious:(int)index withArg2:(NSString *)date
{
NSLog(@"%@",date);
NSLog(@"%d",index);
for (int i=0;i < index; i++)
{
[final_X replaceObjectAtIndex:i withObject:@""];
}
}
_product
. 您的“保留”方法是不必要的,您正在泄漏_product
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.