2012-03-21 1 views
0

Я работаю над приложением, и мне нужно сохранить некоторые данные в словаре, а затем я должен загрузить эти данные и показать пользователю все параметры, сохраненные пользователем. Когда я получаю данные из словаря, он сбрасывается во второй раз не в первый раз и каждый раз записывает разные журналы сбоев. какПочему приложение выдает данные из словаря?

-[UIDeviceRGBColor objectAtIndex:]: unrecognized selector sent to instance 0x68c22d0 

или

[UIControlTargetAction count]: unrecognized selector sent to instance 0x68683d0 

или

0 : <CFString 0x687cb30 [0x124eb38]>{contents = "dish1"} = UIDeviceWhiteColorSpace 0 0.5 

мой код это

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
   if (tableView == menuTableView) { 

       [optionsView addSubview:topScrollView]; 
       optionFlag=NO; 
       [self optionScreenMethod:indexPath.row]; 
       NSString *dishSelect=[NSString stringWithFormat:@"dish%d",indexPath.row]; 
       NSMutableArray *dishesArray=[[NSMutableArray alloc]init]; 
       NSMutableArray *dishDicArray=[[NSMutableArray alloc]init]; 
       dishesArray=[dishDictionary objectForKey:dishSelect]; 
       NSLog(@"%d",[dishesArray count]); 
       if ([dishesArray count]>0) { 
           optionFlag=YES; 
       }else{ 
           for (int i=0; i<[tempStr intValue]; i++) { 
               DishData *dishData=[[DishData alloc]init]; 
               dishData.dishTitle=(NSMutableString*)[[tableMenuArray objectAtIndex:indexPath.row] itemName]; 
               dishData.accompArrayIndex=nil; 
               dishData.cookArrayIndex=nil; 
               dishData.dishComent=nil; 
               dishData.nonMandArray=nil; 
               [dishDicArray addObject:dishData]; 
           } 
           [dishDictionary setObject:dishDicArray forKey:dishSelect]; 
       } 
       //[dishesArray release]; 
       //[dishDicArray release]; 
       dishSelectRow=indexPath.row; 
     //  NSString *dishSelect=[NSString stringWithFormat:@"dish%d",indexPath.row]; 
        
       [isSelected removeAllObjects]; 
       [isSelectedAccompArray removeAllObjects]; 
       [isSelectedCookArray removeAllObjects]; 
       [self defaultDataArray]; 
       [accompmentTblView reloadData]; 
       [cookingTblView reloadData]; 
       [nonMandTblView reloadData]; 
       [nonMandtSelectOptionArray removeAllObjects]; 

       optionsView.hidden=NO; 

   } 
+0

где вы определяете «dishDic tionary "? – LuisEspinoza

+0

на уровне класса. – Mashhadi

+0

@Mashhadi Я отредактировал ответ, проверьте это. Пусть это будет полезно для вас. – Kuldeep

ответ

0
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

     //If possible make a singleton instance here of "dishDictionary" may solve your issue of crashing (Rather diclare it at the class level) 
     //if(!dishDictionary) 
      dishDictionary=[[NSMutableDictionary alloc]init]; 

     .......... 

     //Replace this line : 
     NSMutableArray *dishDicArray=[[NSMutableArray alloc]init]; 

     to 

     NSMutableArray *dishesArray=[[NSMutableArray alloc]initWithArray:[dishDictionary objectForKey:dishSelect]]; 

     and remove 
     dishesArray=[dishDictionary objectForKey:dishSelect]; 

     .......... 
     //may will not crash than try this 
} 
+0

нет разница. :( – Mashhadi

+0

Thanx его работает, но он снова сработает, когда этот код запускается в 3-й раз на этой строке. NSMutableArray * dishesArray = [[NSMutableArray alloc] initWithArray: [dishDictionary objectForKey: dishSelect]]; – Mashhadi

+0

Я бы предложил выделить, когда он вызывает didselect. Попробуйте отредактированный код, я просто прокомментирую 1 строку из кода. И если он работает хорошо, чем plg, то принимайте ответ как истинный :), а просто комментируя ответ – Kuldeep