tableViewController에있는 tableView가있는 응용 프로그램이 있습니다. 사용자가 셀을 클릭 할 때 코드에 지정된 위치로 길 찾기를 제공하도록하려고합니다. 지금은 테스트를 위해 NSLog를 추가했습니다.테이블 뷰 셀을 클릭하면 경로가있는 맵이 열림
모든 위치 이름을 포함하는 tableData라는 viewDidLoad에 NSArray가 있습니다. 그것들은 셀로 올바르게 출력됩니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyCell"];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [mainDelegate.distances objectAtIndex:indexPath.row];
return cell;
}
문제는 아래 코드에 있습니다.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[cell.textLabel.text] isEqualToString:@"Location 1") {
NSLog(@"Location 1 clicked");
}
}
세포. in 문에서 "선언되지 않은 식별자 '셀'사용"오류가 발생하고 잘못된 점을 파악할 수 없습니다.
didSelectRowAtIndexPath:
방법에서
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([[cell.textLabel.text] isEqualToString:@"Location 1"])
{
NSLog(@"Location 1 clicked");
}
}
didSelectRowAtIndexPath에서, 당신은 당신이 셀의 뷰 객체를 사용하는 대신 cellForRowAtIndexPath에있는 것처럼 기본 데이터 소스 (tableData)를 사용합니다. – Anna