Re: Adding Rows to a Table View
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Hi Fritz and Matt, Thanks for taking the time to reply. On 1 Apr 2010, at 00:30, Matt Neuburg wrote: On 31 Mar 2010, at 21:17, Fritz Anderson wrote: On 31 Mar 2010, at 1:52 PM, Dave wrote: ... [myObjectNameString release]; [myFactYearString release]; [myFactMonthString release]; [myFactDayString release]; [myFactSourceDatabaseString release]; [myFactTextString release]; — F None of the other TableView call backs gets called. Thanks again for your help. All the Best Dave I've copied the code below myItemCount = [theItemDictionaryArray count]; [self.mFactDetailArray addObjectsFromArray:theItemDictionaryArray]; [myIndexPathArray release]; } - (NSInteger)numberOfSectionsInTableView:(UITableView*)theTableView { return 1; } myDictionary = [self.mFactDetailArray objectAtIndex:theIndexPath.row]; _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.apple... And one other thought - you say you're gathering this data in a "secondary thread", so be sure to jump out to the main thread before calling something like insertRowsAtIndexPaths:withRowAnimation or reloadData. m. I confirm that the method that calls insertRowsAtIndexPaths:withRowAnimation/reloadData is called from the Main Thread. Fix this first; I'm surprised it doesn't crash your app almost immediately: Review the memory-management rules. You don't take ownership of any of the objects you get from myDictionary, and you must not release them. If you're using Xcode 3.2 or later, try Build > Build and Analyze from time to time. If you're not, Snow Leopard is only $30. The "release" calls were actually if'ed out of the version I was running. This was the remnants of some debug code I'd added ages ago, I've removed the offending lines now. I actually have Snow Leopard, but I'm using Leopard at the moment. I can easily move over to Snow Leopard, I will do that over the weekend. For the rest: If it were me, I'd note that insertRowsAtIndexPaths:withRowAnimation: takes an array, allocate an NSMutableArray and accumulate the paths into it at each iteration of the loop, not doing the insertRows..., reloading the table, or the re-titling of the controller until I was out of the loop. After that, I'd break after the end of the loop, and see if the index-path array contained as many objects as I expected, and that they were all unique. I think I'd have a better picture then. I've recoded the method so that it does as you said and build an array and then just makes one call to "insertRowsAtIndexPaths:withRowAnimation:". However it still fails to update the table. None of the expected call backs are called. I've tried this with both the row and section starting at 0 and at 1. Could someone tell me what the correct index starting point is? (e.g. 0 or 1). "numberOfSectionsInTableView" -- Gets called once and always returns 1. "tableView: numberOfRowsInSection" -- Gets called once and returns the number of items in the initially empty array (0). I've tried it with/without calls to reloadData. I've stepped through the code and at the end of the loop there is the correct number of items in the "myIndexPathArray". In the most case the number of items passed to the "parser: didParseItems" will be 10. This is the current size of the batch of items to buffer before updating the main Array and the TableView. Any ideas on what to try next? I've googled this and found a number of threads from people with the same or similar problems but have not found anything on what is causing the problem and how to fix it. - (void)parser:(ParserBase*)theParser didParseItems:(NSArray*) theItemDictionaryArray { NSEnumerator* myArrayEnumerator; NSDictionary* myDictionary; NSString* myObjectNameString; NSString* myFactYearString; NSString* myFactMonthString; NSString* myFactDayString; NSString* myFactSourceDatabaseString; NSString* myFactTextString; static int myObjectCount = 0; NSMutableArray* myIndexPathArray = nil; int myItemCount; NSIndexPath* myIndexPath; myIndexPathArray = [[NSMutableArray alloc] init]; myArrayEnumerator = [theItemDictionaryArray objectEnumerator]; while (myDictionary = [myArrayEnumerator nextObject]) { myIndexPath = [NSIndexPath indexPathForRow:myObjectCount inSection:0]; [myIndexPathArray addObject:myIndexPath]; myObjectNameString = [myDictionary objectForKey:[ParserXML parserObjectFieldName]]; myFactYearString = [myDictionary objectForKey:kField_FactYear]; myFactMonthString = [myDictionary objectForKey:kField_FactMonth]; myFactDayString = [myDictionary objectForKey:kField_FactDay]; myFactSourceDatabaseString = [myDictionary objectForKey:kField_FactSourceDatabase]; myFactTextString = [myDictionary objectForKey:kField_FactText]; NSLog(@"********************** item:%d",myObjectCount); #if 0 NSLog(myObjectNameString); NSLog(myFactYearString); NSLog(myFactMonthString); NSLog(myFactDayString); NSLog(myFactSourceDatabaseString); NSLog(myFactTextString); #endif myObjectCount++; } [self.mFactTableView beginUpdates]; [self.mFactTableView setEditing:YES animated:YES]; [self.mFactTableView insertRowsAtIndexPaths:myIndexPathArray withRowAnimation:UITableViewRowAnimationBottom]; //[self.mFactTableView reloadData]; [self.mFactTableView endUpdates]; - (NSInteger)tableView:(UITableView*)theTableView numberOfRowsInSection:(NSInteger)theSection { int myCount; myCount = [self.mFactDetailArray count]; return myCount; } - (UITableViewCell *)tableView:(UITableView*)theTableView cellForRowAtIndexPath:(NSIndexPath *)theIndexPath { static NSString* myFactCellIdentifier = @"FactCell"; UITableViewCell* myNewCell = nil; NSDictionary* myDictionary = nil; NSString* myObjectNameString = nil; NSString* myFactYearString = nil; NSString* myFactMonthString = nil; NSString* myFactDayString = nil; NSString* myFactSourceDatabaseString = nil; NSString* myFactTextString = nil; //static int myObjectCount = 0; myNewCell = [theTableView dequeueReusableCellWithIdentifier:myFactCellIdentifier]; if (myNewCell == nil) { myNewCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myFactCellIdentifier] autorelease]; } myObjectNameString = [myDictionary objectForKey:[ParserXML parserObjectFieldName]]; myFactYearString = [myDictionary objectForKey:kField_FactYear]; myFactMonthString = [myDictionary objectForKey:kField_FactMonth]; myFactDayString = [myDictionary objectForKey:kField_FactDay]; myFactSourceDatabaseString = [myDictionary objectForKey:kField_FactSourceDatabase]; myFactTextString = [myDictionary objectForKey:kField_FactText]; myNewCell.textLabel.text = myFactSourceDatabaseString; return myNewCell; } - (BOOL)tableView:(UITableView *)theTableView canEditRowAtIndexPath: (NSIndexPath *)theIndexPath { return YES; } This email sent to site_archiver@lists.apple.com
participants (1)
-
Dave