유니버설 마스터 세부 정보 애플리케이션을 만들었습니다. 나는 IPad와 iPhone을 위해 Storyboard를 사용했다. 나는 실제로 마스터 테이블 뷰에 제시 될 필수 데이터를 검색하기 위해 HTTP 요청을 만들고있다. requestFinished 메서드에서 tableview 데이터를 다시로드합니다.IPAD 대 iphone TableView 행
- (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에서 섹션 수를 출력합니다. 내가 NSLog를 사용하는 경우
- (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];
}
그래서, 2 ConversationList 내 cellForRowAtIndexPath에서 1
내가 섹션의 46
수를 계산 내가 섹션에서 객체의 수를 얻을 얼마나 많은 부와 행을 볼 수 내 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의 값 개수를 반환하면 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 시뮬레이터에서 첫 번째 두 셀 중 하나를 선택하면 예상대로 (빈) 상세보기가 표시됩니다. 그러나 처음 두 개 이상의 값을 선택하면 다음 오류가 발생합니다.
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
모든 도움을 주시면 감사하겠습니다. 미리 감사드립니다. 팀
도움을 주셔서 대단히 감사드립니다. 핵심 데이터를 사용하여 코드를 정리하고이 문제를 다시 검토합니다. –
피드백에 다시 한 번 감사드립니다. Universal App을 만들 때 Core Data를 선택하고 Core Data를 올바르게 사용하지 않았습니다. 핵심 데이터를 활용하지 않았고 백업 및 실행 중입니다. 도움을 감사하십시오. –