簡體   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