iPhone:无法将数组的实例复制到其他数组
不知道为什么会发生这种情况我有一个方法 getOutage ,
NSArray *fetchedOutages = [context executeFetchRequest:fetchRequest error:&error];
if (error) {
NSLog(@"Error in Core Data: %@", [error description]);
}
return fetchedOutages;
当我尝试将此数组复制到 listOutage (这是一个属性)时,
@property (nonatomic, retain) NSArray *listOutage
它返回一个托管对象数组我尝试在 didRowSelectMethod 中像这样复制这个数组
if (listOutage) {
NSLog(@"Its there");
[listOutage release];
}
listOutage=[[NSArray alloc] initWithArray:[self getOutage]];
我尝试了各种其他方法但是那么所有这些都失败了。
此 getoutage 方法返回 5 个对象,五个对象在 listOutage 中复制,但是当我尝试访问 listOutage 元素时,它们显示为“超出范围” 请帮助我克服这个问题,我必须将其传递给下一个 ViewController。
提前致谢
Dont why this is happening I have a method getOutage which returns an array of managed objects
NSArray *fetchedOutages = [context executeFetchRequest:fetchRequest error:&error];
if (error) {
NSLog(@"Error in Core Data: %@", [error description]);
}
return fetchedOutages;
when I try to copy this array to listOutage (this is a property)
@property (nonatomic, retain) NSArray *listOutage
I tried to copy this array like this in didRowSelectMethod like this
if (listOutage) {
NSLog(@"Its there");
[listOutage release];
}
listOutage=[[NSArray alloc] initWithArray:[self getOutage]];
I tried various other methods but all of then are failing.
This getoutage method returns 5 objects five objects got copied in listOutage but when I try to access the listOutage elements they are displayed as 'out of scope'
Please help me to overcome this I have to pass this to next ViewController.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当有属性时,使用“self.property”而不是“property”,这样,当其他人读取您的代码时,如果您指的是 ivar 还是属性,那就更明显了。
如果使用self.property,则无需编写
,只需编写
release即可,retain将由@synthesize属性生成的get/set方法处理。
when there is a property, use 'self.property' instead of 'property' that way, when somebody else reads your code it is more obvious if you mean an ivar or a property.
if you use self.property, you do not need to write
instead, just write
the release and retain will be handled by the get/set method generated by the @synthesize property.