오른쪽에 섹션, 검색 및 알파벳 스트립이 포함 된 멋진 TableView를 만들었습니다.섹션과 검색이있는 PrepareForSeque를 UITableView에 코딩하는 방법
"A"가 제대로 작동하지 않는 것을 알아 채기 전까지는 테스트를 거쳤습니다. 이유를 발견했습니다. PrepareForSegue에서 행에서 찾은 객체를 전달했지만 섹션에 관심을 기울이지 않았습니다.
스택 오버플로를 검색하여 수행하려고하는 것과 같은 것을 발견했지만 didSelectRowAtIndexPath에서 코딩 중이며, 그렇지 않은 경우를 대비합니다. 그리고 코드를 작동시킬 수 없었습니다.
첫 번째 질문은 두 가지 방법 사이의 관계는 무엇입니까? 나는 스토리 보드를 사용하고 있기 때문에 나는 그 섹슈얼을 고수해야한다고 생각한다. 그렇다면 어떤 직원 객체를 통과 시킬지 어떻게 알 수 있습니까?
도움을 주시면 감사하겠습니다.
브라이언
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
employee *dtlEmployee = [_employees objectAtIndex:indexPath.row];
self.detailViewController.detailItem = dtlEmployee;
}
else
{
// employee *dtlEmployee;
//
// int row = indexPath.row;
// int section = indexPath.section;
//
// NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:row inSection:section];
//
// [self.tableView deselectRowAtIndexPath:newIndexPath animated:NO];
// UITableViewCell *cell = [tableView cellForRowAtIndexPath:newIndexPath];
//
// dtlEmployee = [_employees objectAtIndex:newIndexPath];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
employee *dtlEmployee;
// int row = [[self.tableView] indexPath.row];
// int section = [self.tableView indexPath.section];
// NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:row inSection:section];
// dtlEmployee = [_employees objectAtIndex:newIndexPath];
// NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow];
// NSUInteger selectedRow = selectedRowIndexPath.row;
// NSUInteger selectedSection = selectedRowIndexPath.section;
// NSArray *tmpArray = [_employees objectAtIndex:[self.tableView indexPathForSelectedRow]];
// dtlEmployee = [tmpArray objectAtIndex:selectedRowIndexPath.row];
// dtlEmployee = [tmpArray objectAtIndex:indexPath.row];
//
// dtlEmployee = [_employees objectAtIndex:selectedRowIndexPath.]
//
if (isSearching)
{
dtlEmployee = [self.filteredEmployees objectAtIndex:self.searchDisplayController.searchResultsTableView.indexPathForSelectedRow.row];
}
else
{
dtlEmployee = [_employees objectAtIndex:[self.tableView indexPathForSelectedRow].row];
}
[[segue destinationViewController] setDetailItem:dtlEmployee];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [self.tableView dequeueReusableCellWithIdentifier: CellIdentifier];
//cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (isSearching)
{employee *thisEmployee = [self.filteredEmployees objectAtIndex:indexPath.row];
cell.textLabel.text = thisEmployee.fullName;}
else
{employee *thisEmployee = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.text = thisEmployee.fullName;}
return cell;
}
당신은 당신의 cellForRowAtIndexPath 방법을 포함시겠습니까? – Gavin
네, –