불행히도, 애플은 테스트하지 않았다. tutorial. "Locations"데모는 실제로 버그이며 편집 버튼은 존재하지 않습니다. 나는 오타가 없다. 처음에는 복사 & 붙여 넣기를하지 않았습니다. 그 후, 나는 또한 &을 붙여 넣으려고했습니다. 관련 코드가 많이 빠져 있습니다.사과 버기 "위치"예제가 작동하려면 어떻게해야합니까?
그들은 단순히 어느 곳, 어느 편집 버튼을 생성하지 않고,보기에서이 부하를 않았다 수행
- (void)viewDidLoad {
[super viewDidLoad];
// Set the title.
self.title = @"Locations";
// Configure the add and edit buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem; // WTF?
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addEvent)];
addButton.enabled = NO;
self.navigationItem.rightBarButtonItem = addButton;
// Start the location manager.
[[self locationManager] startUpdatingLocation];
/*
Fetch existing events.
Create a fetch request; find the Event entity and assign it to the request; add a sort descriptor; then execute the fetch.
*/
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
// Order the events by creation date, most recent first.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"creationDate" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];
// Execute the fetch -- create a mutable copy of the result.
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
}
// Set self's events array to the mutable array, then clean up.
[self setEventsArray:mutableFetchResults];
[mutableFetchResults release];
[request release];
}
내가 전체 튜토리얼을 통해 가서 내가 세포를 삭제할 수 없습니다 것을 제외하고, 지금까지 작동하기 때문에 그들은 바로 여기 편집 버튼을 얻지 못했습니다.
// Setup the buttons for the navigation bar
editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editEvent)];
self.navigationItem.leftBarButtonItem = editButton;
하지만 이제 editEvent 방법의 구현과 같이하는 작업은 다음과 같습니다
나는 -viewDidLoad에서이 줄을 자신 것을 해결하려고? 불행히도이 모든 것들은 핵심 데이터 튜토리얼에서 완전히 빠져 있습니다.
어디에서 editButtonItem을 정의합니까? 나는 UITableView 및 UITableViewController에 대한 문서를 조사했다. 그들 중 누구도 "editButtonItem"이라는 것을 정의하지 않습니다. 또한 xcode에서 자동 완성 기능이 제공되지 않습니다. 그래서 확실히 코드가 누락되었습니다. 그러나 이것에 대한 또 다른 해결 방법이 있습니다;) – openfrog
그것이 누락되지 않았 음을 약속드립니다. 내 대답은 그것에 대한 설명서에 링크되어 있습니다. editButtonItem은 UIViewController에 정의되어 있습니다 (UITableViewController는 UIViewController의 하위 클래스입니다). – gerry3