我有一个 NSMutableArray,其中包含名为 PropertyData 的模型类的实例(只有属性,没有方法)。在我的应用程序中,有一个“在 map 上查看”按钮,点击该按钮后,会在 map View Controller 的属性中设置此 NSMutableArray,然后再将其 View 推到导航顶部。 map View Controller 成功接收了这个数组(使用 NSLOG 我打印出了 map View Controller 中接收到的总项目),但是当循环它时,我得到了这个错误:
[PropertyData lat] message sent to deallocated instance
知道为什么吗?
感谢您的帮助,
史蒂芬
附注:
在第一个 View Controller 中,数据存储到名为 rqst_entries 的 ivar(在界面中声明为 NSMutableArray 属性,然后合成),以下是它如何切换到 map View :
-(void)show_map
{
PropertiesMapViewController *pMapView = [[PropertiesMapViewController alloc] init];
pMapView.entries = self.rqst_entries; // pMapView.entries is alsi a NSMutableArray
[self.navigationController pushViewController:pMapView animated:YES];
}
这是崩溃的代码:
if(self.entries != nil)
{
NSLog(@"received items count=%d",[self.entries count]);
NSNumberFormater *nf = [[NSNumberFormater alloc] init];
for(PropertyData *property_data in self.entries)
{
if(property_data==nil) continue;
[nf setNumberStyle:NSNumberFormatterDecimalStyle];
// CRASH OCCURS HERE:
NSNumber *lat = [nf numberFromString:property_data.lat];
}
}
最佳答案
您应该确保 PropertiesMapViewController
的 entries
属性具有保留属性:
@property (nonatomic, retain) NSMutableArray * entries;
关于iphone - 将实例传递给另一个 View Controller 后为 "message sent to deallocated object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7413785/