I have used NSMutable Dictionary and NSMutable Array. The datas are to be stored and retrieved from plist(Documents Directory) using NSArray of NSMutable Dictionary.
Edit:
I have six buttons in the scroll view, on clicks the button, the data is to be displayed in the table view using XML parsing. i have put the data into the plist and retrieved from plist and displayed in the table view. In the table view, i have one button as footer view. On clicks the button, the next items are to parsed and displayed in the table view. The next parsing contents are adding to the previous contents. I have used NSMutable Dictionary for storing the data into the plsit.
Here my code is,
The return array is returns the parsing details and.
-(void)callFromSecondaryThread:(NSMutableArray *)returnArray{
if([returnArray count] > 0)
{
for(NSMutableArray *arr in returnArray)
{
//[copyArray addObjectsFromArray:returnArray];
//[copyArray addObject:returnArray];
//[ ???? ??? ??????? ?????? ]
}
[self.table reloadData];
}
//First time save the contents in the plist and loading the content from the plist and displayed in the table view
-(void)startParsingBasedOnSelectedTabValue:(NSString *)strValue {//button value
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (![self checkFileIsThere:tagString]) { //checks the plist is available or not, if its not available, then create a new file. i have created separate plist file for each buttons.
if([copyArray count] > 0)
{
[copyArray removeAllObjects];
}
feedDictionary = [[NSMutableDictionary alloc]init];
//send url for parsing [self parsingMethod];
[feedDictionary setObject:copyArray forKey:tagString];
[feedDictionary writeToFile:[self saveFilePath:tagString] atomically:NO];
[feedDictionary release];
} else{
NSString *stringPtah = [self saveFilePath:tagString];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:stringPtah];
NSMutableArray *arrArray = [dictionary objectForKey: tagString];
copyArray = [arrArray copy];
}
[self.table performSelectorOnMainThread:@selector(reloadData) withObject:开发者_运维问答nil waitUntilDone:NO];
[pool drain];
}
//On clicks the next 10 details button,
-(void) details:(NSString *) strpageCount
{
if ([self checkFileIsThere:tagString]) {
[[NSFileManager defaultManager] removeItemAtPath:[self saveFilePath:tagString] error:NULL]; // remove the old plist here
NSMutableDictionary *feedDictionary1 = [[NSMutableDictionary alloc]init];
[self parsingMehods];
[feedDictionary1 setValue:copyArray forKey:tagString];
[feedDictionary1 writeToFile:[self saveFilePath:tagString] atomically:NO];
[pageDictionary setValue:pString forKey:tagString];
[feedDictionary1 release];
[self.table reloadData]; // After writing the file in the plist, i just reload the table data and displayed the contents in the table view.
}
}
But i can get successfully added the datas in the copyArray sometimes only. which means, i have click the next button after loading the view, it works fine. But if i moved the next button and visits that view and come back to the first view and clicks the next button, i get crashed my apps.
I can get the datas in the returnArray and copyArray is my main array and its used to display the contents(CellforRowatindex).ReturnArray is a mutable array and its contains the title,date,image,etc.,
On clicks the (next 10 details) button, i have removed my old plist and create a new plist with the new contents.(For Eg:first plist has 10 contents in the copy array and returns 4 new content. it would be added 14 contents in the copy array and displayed in the table view). In first time loading my apps, clicks the next button, the array will be added successfully. But i visit the the remaining buttons and details, then comeback to the view, and clicks the next button, i get crashed my apps and get this exception,
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'
I have spent a many hours to this problem and till haven't get a solution.
Please mentioned what i have done wrong in my code..
Please Guide me?.
Thanks!
The line copyArray = [arrArray copy];
should be copyArray = [arrArray mutableCopy];
. You are getting the error because copyArray
is immutable.
精彩评论