2010-03-11 1 views
1

TableView 프로그래밍 가이드를 따르려고하는데 가이드에서 직접 코드를 복사하고 있지만 컴파일하려고하면 "SimpleEditableListAppDelegate undeclared"가 나타납니다. Google은 프로그래밍 가이드 만 반환합니다. SimpleEditableListAppDelegate는 무엇이며 어떻게 사용합니까?SimpleEditableListAppDelegate 란 무엇입니까?

답변

4

SimpleEditableListAppDelegate은 응용 프로그램의 대리인입니다. 새로운 Xcode 프로젝트를 만들 때 자동으로 생성되는 클래스입니다. 코드가 컴파일되지 않는 이유는 SimpleEditableListAppDelegate 클래스가 프로젝트에 존재하지 않기 때문입니다. 프로젝트의 이름이 테이블보기 프로그래밍 가이드의 것과 다르기 때문입니다. 코드의 어딘가에 존재하지 않는 클래스에 대한 참조가 있기 때문에 "SimpleEditableListAppDelegate undeclared"오류가 나타납니다.

Xcode의 파일 사이드 바에서 앱 대리인 클래스의 이름을 볼 수 있어야합니다. 따라서 SimpleEditableListAppDelegate이 실제 위임자 클래스 이름으로 바뀌는 것을 볼 수 있습니다. 또는 SimpleEditableListAppDelegate의 모든 인스턴스를 [[UIApplication sharedApplication] delegate]으로 바꿉니다.

iPhone 프로그래밍의 기본 사항을 먼저 이해해야하는 것처럼 들리므로 this을 살펴볼 수 있습니다. 나는 우리가 모든 애플이 소스에서 찾고있는 말을하는 것이 안전하다고 생각

+0

아이폰 프로그래밍의 기초를 배우려는 것이 분명했다. 감사. – Shawn

3

...

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    // If row is deleted, remove it from the list. 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     SimpleEditableListAppDelegate *controller = (SimpleEditableListAppDelegate *)[[UIApplication sharedApplication] delegate]; 
     [controller removeObjectFromListAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 

SimpleEditableListAppDelegate는 자신의 예를 들어 클래스의 이름입니다. 귀하의 코드에서 테이블보기 (예 : MyAppDelegate)에 대한 대리인의 이름을 사용하거나 "[self removeObjectFromListAtIndex];를 사용하기 만하면됩니다. 컨트롤러를 만드는 대신에 나를 위해 잘 작동했습니다.

removeObjectFromListAtIndex는 테이블보기 데이터를 지원하는 배열의 내용을 삭제하기 위해 작성하는 함수의 임의의 이름입니다. 함수를 사용하지 않고 대신 몇 줄의 코드 만 사용했습니다. 그것은 나를 위해 일한 방법은 다음과

은 ...

난이 도움이되기를 바랍니다
if (editingStyle == UITableViewCellEditingStyleDelete) { 
    // Update Model 
    NSMutableArray *work_array = [NSMutableArray arrayWithArray:self.city_table]; 
    [work_array removeObjectAtIndex:indexPath.row]; 
    self.city_table = [NSArray arrayWithArray:work_array]; 
    [[NSUserDefaults standardUserDefaults] setObject:self.city_table forKey:KEY_CITY_TABLE]; 

    // Update View 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 

... K @ Z입니다!