0

我有一个 NSMutableDictionary ,我添加到一些我异步接收的自定义 NSObjects 中。每次收到新数据时,我都会清除字典然后添加新对象。然后将数据推送到另一个类“UIView”以呈现字典中的内容。我一直在收到 SIGABRT 异常,据我所知,这意味着尝试访问的对象已被释放。我已经尝试过同步块,创建一个可变副本并获取所有值,但现在没有任何效果我的问题是如何实现同步

这是一个代码片段,

@interface MyAltViewController : UIViewController
{
   __block NSMutableDictionary *currentDataList;
    TestUIVIEW *myUIVIEW
}
@implementation MyAltViewController

......
- (void)viewDidLoad
{
   currentDataList = [[NSMutableDictionary alloc] initWithCapacity:10];
   [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(processDataMessag:)
                                         name:view_Data object:nil];
}
.....
-(void)processDataMessag:(NSNotification *) notification
{
  [currentDataList removeAllObjects];
  NSArray tmpAr= (NSArray*) [notification object]
  dispatch_async(dbQueue, ^(void)
  {
     /// Loop through the array and process the data then add to NSDictionary 

     [self pushtoMUViewLayer:currentDataList];
  });

}
.........
 -(void)pushtoMUViewLayer:(NSMutableDictionary *)ina
 {
     /// Even here if i try to access and object within 
     /// currentDataList and just a specific NSString i get the SIGABRT
    [myUIVIEW updateWithData:ina];
 }
 //////////////////////////////////////////////////
 @interface TestUIVIEW : UIView
 {
    NSMutableDictionary *mdata;
    UIImage *outputImage ;

 }
 @property (assign) NSMutableDictionary *mapdata;
 @property (retain) UIImage *outputImage ;

  @implementation TestUIVIEW
    .......
  -(void)updateWithData:(NSMutableDictionary *)data
  {
     mdata = [data retain]; // ??? not  sure how to set it correctly
      dispatch_async(dispatch_get_main_queue(), ^(void)
      { 
        [self CreateImage];
        [self setNeedsDisplay];
      });
  }
  -(void) CreateImage
  {
    NSString *key;
    for(key  in mapdata)
    {
        DataMessage *tmpData= (DataMessage*)[mapdata objectForKey:key];
        NSString *aID = [ tmpData alt] ;
        double aLat   = [ tmpData lat]  ;
        double aLong  = [ tmpData lon] ;
       /*
          Drawing code  I can Get aLat & A Long
          but it fails with SiABRT when trying to render 
          aID
       /*
    }
  }

  - (void)drawRect:(CGRect)rect
  {
    // Drawing code

   CGPoint imagePoint = CGPointMake(0, 0);

   [outputImage drawAtPoint:imagePoint];

}

/// 如果同步不起作用。我可以使用 NSNotification 来查看我的 currentDataList // 到我的 currentDataList

4

1 回答 1

0

在我访问 NSDictionary 的所有地方添加 @synchronised 块确实解决了这个问题。谢谢大家的意见

于 2013-01-28T19:45:14.153 回答