繁体   English   中英

IPAD与Iphone TableView行

[英]IPAD vs Iphone TableView rows

我已经创建了通用主详细信息应用程序。 我将Storyboard用于iPad和iPhone。 我实际上是在发出HTTP请求以检索将在主表视图中呈现的所需数据。 我从requestFinished方法重新加载tableview数据。

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

NSString *responseString = [request responseString];

ConversationDataController *dataControllerSingleton = [ConversationDataController sharedInstance];

conversationList = [responseString JSONValue];

[dataControllerSingleton setConversationList:conversationList];

[self.tableView reloadData];
}

我将返回的数据存储在dataControllerSingleton中,该数据具有一个称为对话列表的NSMutableArray属性。

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

- (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节中获得了对象数ConversationList count 46
节数1

在我的cellForRowAtIndexPath中,我从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的主视图中都看到了两个值。 当在主视图中选择这些值之一时,将进入详细信息视图(目前为空)。 对于显示的两行,此操作没有任何错误。

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

- (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模拟器上,如果我选择了前两个单元格之一,那么将按预期显示(空)详细信息视图。 但是,当我选择前两个值之外的任何值时,都会收到以下错误;

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

任何帮助将不胜感激。 提前致谢。 提姆

请将libz.dylib添加到您的项目中。 可以将其添加到“构建阶段”选项卡中。 那里有Binarry库部分的链接。 单击“ +”符号,然后将libz.dylib添加到您的项目中

如果您使用多个部分(看起来像您一样),则使用委托方法

tableView:(UITableView *)tableView cellForRowAtIndexPath:

应该真的在处理这个。

您似乎还混用了NSFetchedResultsController来计算节和行的数量,然后使用属性self.conversionList返回行数。 但是对于哪个部分。 如果要使用核心数据,则不要将单例与数组一起使用,而是将Web服务器中的数据缓存到核心数据表中,然后在

- (NSFetchedResultsController *)fetchedResultsController

方法。

另外,您还要混合使用self.conversionList和

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

他们都一样吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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