ユニバーサルマスター詳細アプリケーションを作成しました。iPadとiPhoneにはストーリーボードを使用しました。私は実際に、マスターテーブルビューに表示される必要なデータを取得するためのHTTPリクエストを作成しています。requestFinishedメソッドからテーブルビューデータをリロードします。
- (void)requestFinished:(ASIHTTPRequest *)request {
NSString *responseString = [request responseString];
ConversationDataController *dataControllerSingleton = [ConversationDataController sharedInstance];
conversationList = [responseString JSONValue];
[dataControllerSingleton setConversationList:conversationList];
[self.tableView reloadData];
}
返されたデータを、conversationListというNSMutableArrayプロパティを持つdataControllerSingletonに格納します。
numberOfRowsInSectionで、fetchedResultsControllerに基づいてセクション内のオブジェクトの数を出力します。また、NSMutableArrayのconversationListの値の数も出力します。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のオブジェクトの数が取得されます。ConversationListcount46セクション
の数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の両方のマスタービューに2つの値が表示されます。マスタービューでこれらの値のいずれかを選択すると、詳細ビューに移動します(今のところ空です)。これは、表示される2つの行に対してエラーなしで機能します。
numberOfRowsInSectionを変更して、NSMutableArrayの値の数を返す場合、return [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シミュレーターで、最初の2つのセルのいずれかを選択すると、期待どおりに(空の)詳細ビューが表示されます。ただし、最初の2つ以外の値を選択すると、次のエラーが発生します。
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
どんな援助でも大歓迎です。前もって感謝します。ティム