2013-04-01 29 views
1

我在章節DC類中獲取所有章節,也獲取區域,我在chapterDC類中擁有selectedRegion的屬性,並想通過chapterDC將我的區域數據傳遞到regionDC,但是我的日誌消息始終爲0並且爲null,知道我在做什麼錯誤如何將數據從一個實體傳遞到其他實體類?

-(NSMutableArray *)getAllChapters 
{ 
    NSMutableArray *returnArray = [[NSMutableArray alloc] init]; 

    NSString *url = [NSString stringWithFormat:@"%@get_all_chapters",kWSURL]; 
    NSDictionary * returnDict = (NSDictionary *) [self callWebService:url]; 
    if([[returnDict objectForKey:@"status"] isEqualToString:@"success"]) 
    { 
     NSDictionary * responseDict = (NSDictionary *) [returnDict objectForKey:@"response"]; 
     NSArray *resultArray = [responseDict objectForKey:@"result"]; 

     for(NSDictionary *chapterDict in resultArray) 
     { 
      ChapterDC * chapter = [[ChapterDC alloc] init]; 
      chapter.ChapterDC_ChapterID=[[chapterDict objectForKey:@"ChapterID"]intValue]; 
      chapter.ChapterDC_ChapterName = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"ChapterName"]]; 
      chapter.selectedRegion.RegionDC_RegionID=[ [chapterDict objectForKey:@"RegionID"]intValue]; 
      NSLog(@"%d",chapter.selectedRegion.RegionDC_RegionID); 
      chapter.ChapterDC_AddressLine1 = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"AddressLine1"]]; 
      chapter.ChapterDC_AddressLine2 = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"AddressLine2"]]; 
      chapter.ChapterDC_AddressLine3 = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"AddressLine3"]]; 
      chapter.ChapterDC_Email = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"Email"]]; 
      chapter.ChapterDC_URL = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"URL"]]; 
      chapter.ChapterDC_FacebookURL =[ NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"FacebookURL"]]; 
      chapter.ChapterDC_LinkedInURL = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"LinkedInURL"]]; 
      chapter.ChapterDC_PhoneNumber =[ NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"PhoneNumber"]]; 
      chapter.ChapterDC_Postcode = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"Postcode"]]; 
      chapter.ChapterDC_TwitterURL = [NSString stringWithFormat:@"%@", [chapterDict objectForKey:@"TwitterURL"]]; 

      NSDictionary * regionDict = (NSDictionary *) [returnDict objectForKey:@"region"]; 

      { 
      chapter.selectedRegion = [[RegionDC alloc] init]; 
      chapter.selectedRegion.RegionDC_RegionID = [[regionDict objectForKey:@"RegionID"]intValue]; 
      NSLog(@"%d",chapter.selectedRegion.RegionDC_RegionID); 
      chapter.selectedRegion.RegionDC_RegionName = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"RegionName"]]; 
       NSLog(@"%@",chapter.selectedRegion.RegionDC_RegionName); 
      chapter.selectedRegion.RegionDC_ContactName = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"ContactName"]]; 
      chapter.selectedRegion.RegionDC_Mobile = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"Mobile"]]; 
      chapter.selectedRegion.RegionDC_Landline = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"Landline"]]; 
      chapter.selectedRegion.RegionDC_TrainingURL = [NSString stringWithFormat:@"%@", [regionDict objectForKey:@"TrainingURL"]]; 
      } 
      [returnArray addObject:chapter]; 
     } 
    } 
    return returnArray; 
} 
+0

也許你應該封裝一個NSNumber內的詮釋? – achi

回答

2

更換NSDictionary * regionDict = (NSDictionary *) [returnDict objectForKey:@"region"];

NSDictionary * regionDict = (NSDictionary *) [chapterDict objectForKey:@"region"]; 
+0

謝謝我只是複製粘貼,所以我沒有注意到:)) – NullData

相關問題