简体   繁体   中英

IPAD vs Iphone TableView rows

I have created a Universal Master Details application. I used Storyboard for the IPad and iPhone. I am actually making an HTTP request to retrieve the required data that will be presented in the master tableview. I reload the tableview data from the requestFinished method.

- (void)requestFinished:(ASIHTTPRequest *)request {

NSString *responseString = [request responseString];

ConversationDataController *dataControllerSingleton = [ConversationDataController sharedInstance];

conversationList = [responseString JSONValue];

[dataControllerSingleton setConversationList:conversationList];

[self.tableView reloadData];
}

I store the returned data in dataControllerSingleton which has an NSMutableArray property called conversationList.

In the numberOfRowsInSection, I print out the number of objects in the section based upon the fetchedResultsController. I also print out the number of values in my NSMutableArray conversationList. In numberOfSectionsInTableView I print out the number of sections.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
NSLog(@"Number OF Objects in section %lu",(unsigned long)[sectionInfo numberOfObjects]);
ConversationDataController *dataControllerSingleton = [ConversationDataController sharedInstance];

NSLog(@"ConversationList count %lu",(unsigned long)[dataControllerSingleton.conversationList count]);

return [sectionInfo numberOfObjects];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
NSLog(@"Number of sections: %d",[[self.fetchedResultsController sections] count]);
return [[self.fetchedResultsController sections] count];
}

So, when I use NSLog to see how many section and rows I have I get Number of Objects in section 2 ConversationList count 46
Number of Sections 1

In my cellForRowAtIndexPath I am adding the cell text from my NSMutableArray

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView
                         dequeueReusableCellWithIdentifier:@"ConversationCell"];
[self configureCell:cell atIndexPath:indexPath];

ConversationDataController *dataControllerSingleton = [ConversationDataController sharedInstance];
cell.textLabel.text = [dataControllerSingleton.conversationList objectAtIndex:indexPath.row];

return cell;
}

So, with this setup, I see two values in the master view for both iPhone and iPad. When I select either one of these values in master view, I am taken to the detail view (which is just empty for now). This works without any errors for the two rows that are presented.

If I change numberOfRowsInSection to return the number of values in my NSMutableArray return [self.conversationList count]; I run into errors.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
NSLog(@"Number OF Objects in section %lu",(unsigned long)[sectionInfo numberOfObjects]);
ConversationDataController *dataControllerSingleton = [ConversationDataController sharedInstance];

NSLog(@"ConversationList count %lu",(unsigned long)[dataControllerSingleton.conversationList count]);

//return [sectionInfo numberOfObjects];
return [self.conversationList count];
}

On iPhone simulator, I am presented with the 46 values in the master view. I can select any one of them and I am presented with the (empty) detail view. On the iPad simulator, if I select either one of the first two cells, I am presented with the (empty) detail view as expected. However, when I select any value beyond the first two, I get the following error;

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -     [_PFBatchFaultingArray objectAtIndex:]: index (2) beyond bounds (2)'
*** First throw call stack:
(0x19a5012 0x17cae7e 0x19a4deb 0x156941a 0x15e9511 0x42fe9 0x4ae285 0x4ae4ed 0xeb85b3   0x1964376 0x1963e06 0x194ba82 0x194af44 0x194ae1b 0x249b7e3 0x249b668 0x3feffc 0x40e0d 0x2ac5)
libc++abi.dylib: terminate called throwing an exception

Any assistance would be greatly appreciated. Thanks in advance. Tim

Please add libz.dylib into your project . It can be added in the Build phases tab. There you have link with Binarry libraries section . Click '+' symbol and add libz.dylib to your project

If you are using more than one section (which it looks like you are) then delegate method

tableView:(UITableView *)tableView cellForRowAtIndexPath:

should really be handling this.

You also seem to be mixing the use of NSFetchedResultsController to work out the number of sections and rows, but then using the property self.conversionList to return the number of rows. But for which section. If you want to use Core Data then instead of using a singleton with an array, cache the data from your web server into a core data table and use that in your

- (NSFetchedResultsController *)fetchedResultsController

method.

Also you are mixing the use of self.conversionList &

ConversationDataController *dataControllerSingleton = [ConversationDataController sharedInstance];
dataControllerSingleton.conversationList

are they both the same?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM