IPAD vs Iphone TableView 行 [英] IPAD vs Iphone TableView rows

查看:34
本文介绍了IPAD vs Iphone TableView 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个通用主详细信息应用程序.我在 iPad 和 iPhone 上使用 Storyboard.我实际上是在发出一个 HTTP 请求来检索将在主表视图中显示的所需数据.我从 requestFinished 方法重新加载 tableview 数据.

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];
}

我将返回的数据存储在 dataControllerSingleton 中,它有一个 NSMutableArray 属性,称为 sessionList.

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

在 numberOfRowsInSection 中,我根据 fetchedResultsController 打印出该部分中的对象数.我还打印出 NSMutableArray 对话列表中的值数量.在 numberOfSectionsInTableView 中,我打印出部分的数量.

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];
}

所以,当我使用 NSLog 来查看我有多少节和行时第 2 节中的对象数会话列表计数 46
节数 1

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

在我的 cellForRowAtIndexPath 中,我添加了来自 NSMutableArray 的单元格文本

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;
}

因此,通过此设置,我在 iPhone 和 iPad 的主视图中看到两个值.当我在主视图中选择这些值之一时,我被带到详细视图(现在只是空的).这对显示的两行没有任何错误.

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.

如果我更改 numberOfRowsInSection 以返回 NSMutableArray 中的值数返回 [self.conversationList 计数];我遇到了错误.

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];
}

在 iPhone 模拟器上,我在主视图中看到了 46 个值.我可以选择其中任何一个,然后我会看到(空的)详细信息视图.在 iPad 模拟器上,如果我选择前两个单元格中的任何一个,我会按预期显示(空)详细信息视图.但是,当我选择前两个之外的任何值时,出现以下错误;

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

推荐答案

如果你使用了多个部分(看起来你是)然后委托方法

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.

您似乎还混合使用 NSFetchedResultsController 来计算节数和行数,然后使用属性 self.conversionList 返回行数.但是对于哪个部分.如果您想使用 Core Data,那么不要使用带有数组的单例,而是将来自您的 Web 服务器的数据缓存到一个核心数据表中,然后在您的

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

方法.

您还混合使用 self.conversionList &

Also you are mixing the use of self.conversionList &

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

两者都一样吗?

这篇关于IPAD vs Iphone TableView 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆