2013-01-20 5 views
0

나는 비동기 적으로받는 일부 사용자 지정 NSObject에 NSMutableDictionary를 추가했습니다. 새 데이터를받을 때마다 사전을 삭제 한 다음 새 개체를 추가합니다. 그런 다음 다른 클래스 "UIView"로 데이터를 밀어 넣어 사전에 내용을 렌더링합니다. 나는 내가 아는 한 접근하려고하는 객체가 해제되었음을 의미하는 SIGABRT 예외를 얻고있다. 나는 mututablecopy를 만들고 allvalues을 받고, 동기화 블록을 시도했지만 아무것도 지금은 동기화 여기NSMutableDictionary 및 다중 스레드 액세스

코드 조각이 달성 할 수있는 방법을 내 질문에,

@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]; 

} 

이 /// 경우 그 동기 didnt 한 일을 일했다. NSNotification을 사용하여 현재 데이터 목록 //을 내 currentDataList에 표시 할 수 있습니다.

+0

코드를 보여주십시오, 우리는 마법사가 아닙니다. –

+0

자신을 해결하기 위해 올바른 길을 가고있는 것처럼 보입니다. 알림을 통해 데이터를 어떻게 받습니까? 디버깅을보다 쉽게 ​​만들 수있는 한 가지 방법은 할당 취소되는 객체에 대한 정보로 모든 dealloc을 기록하는 것입니다. 이것은 적어도 당신이 예기치 않게 할당 취소 된 것을 볼 수 있도록해야합니다 ... –

+0

배열을 수정하거나 액세스하는 모든 장소에서'@ synchronize'를 시도 했습니까? NSMutableArray 자체를 동기화 된 객체로 사용하십시오. –

답변

0

NSDictionary에 액세스하는 모든 장소에서 @synchronized 블록을 추가하면 문제가 해결됩니다. 귀하의 의견을 모두 주셔서 감사합니다