简体   繁体   English

IPAD与Iphone TableView行

[英]IPAD vs Iphone TableView rows

I have created a Universal Master Details application. 我已经创建了通用主详细信息应用程序。 I used Storyboard for the IPad and iPhone. 我将Storyboard用于iPad和iPhone。 I am actually making an HTTP request to retrieve the required data that will be presented in the master tableview. 我实际上是在发出HTTP请求以检索将在主表视图中呈现的所需数据。 I reload the tableview data from the requestFinished method. 我从requestFinished方法重新加载tableview数据。

- (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. 我将返回的数据存储在dataControllerSingleton中,该数据具有一个称为对话列表的NSMutableArray属性。

In the numberOfRowsInSection, I print out the number of objects in the section based upon the fetchedResultsController. 在numberOfRowsInSection中,我根据fetchedResultsController打印出该部分中对象的数量。 I also print out the number of values in my NSMutableArray conversationList. 我还打印了NSMutableArray对话列表中的值数量。 In numberOfSectionsInTableView I print out the number of sections. 在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];
}

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 因此,当我使用NSLog查看我拥有多少节和行时,我在第2节中获得了对象数ConversationList count 46
Number of Sections 1 节数1

In my cellForRowAtIndexPath I am adding the cell text from my NSMutableArray 在我的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;
}

So, with this setup, I see two values in the master view for both iPhone and iPad. 因此,通过此设置,我在iPhone和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]; 如果我更改numberOfRowsInSection以返回我的NSMutableArray中的值数,则返回[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. 在iPhone模拟器上,我在主视图中看到46个值。 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. 在iPad模拟器上,如果我选择了前两个单元格之一,那么将按预期显示(空)详细信息视图。 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 . 请将libz.dylib添加到您的项目中。 It can be added in the Build phases tab. 可以将其添加到“构建阶段”选项卡中。 There you have link with Binarry libraries section . 那里有Binarry库部分的链接。 Click '+' symbol and add libz.dylib to your project 单击“ +”符号,然后将libz.dylib添加到您的项目中

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. 您似乎还混用了NSFetchedResultsController来计算节和行的数量,然后使用属性self.conversionList返回行数。 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 如果要使用核心数据,则不要将单例与数组一起使用,而是将Web服务器中的数据缓存到核心数据表中,然后在

- (NSFetchedResultsController *)fetchedResultsController

method. 方法。

Also you are mixing the use of self.conversionList & 另外,您还要混合使用self.conversionList和

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

are they both the same? 他们都一样吗?

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

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