iphone - 将实例传递给另一个 View Controller 后为 "message sent to deallocated object"

标签 iphone ios ios4 uiviewcontroller uinavigationcontroller

我有一个 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]; 
   }

}

最佳答案

您应该确保 PropertiesMapViewControllerentries 属性具有保留属性:

@property (nonatomic, retain) NSMutableArray * entries;

关于iphone - 将实例传递给另一个 View Controller 后为 "message sent to deallocated object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7413785/

相关文章:

iphone - 在 iPhone 应用程序中创建 .swf

iphone - 如何添加一个看起来像 UIAlert 的启动 View

iphone - 网络应用程序与 native 应用程序

ios - OpenGL 更改坐标设置

ios - UISegmentedControl 内部 View 应在显示 View 后调用 API

iphone - 如何使用 Interface Builder 在其他 UI 元素的背景中添加 UIButton?

php - 基于 Web 的方法来确定 iPhone 是否通过 3G 或 Wifi 连接

ios - Xcode、GitHub 和第三方框架

iphone - 为 UIImageView 实现 UITouchDown

ios - 升级应用程序以支持ios5