테이블 뷰가 있고 두 개의 텍스트 필드가있는 사용자 정의 셀을 만들었습니다 ... 텍스트 필드의 텍스트를 코어 데이터에 저장하고 싶습니다. 그런 목적으로 코어 데이터 클래스를 만들었습니다. 핵심 데이터 메서드를 구현하는 방법을 알고 있습니다.텍스트 필드 및 코어 데이터가있는 사용자 정의 셀
사용자가 텍스트를 입력 한 다음 핵심 데이터에 저장되도록 테이블 뷰에 셀을 표시하는 방법을 이해하는 데 문제가 있습니다. 내 이해에서 이러한 단계는 다음과 같습니다.
1 - tableview는 기본적으로 텍스트 필드를 사용하여 사용자 지정 셀을로드하고 표시합니다.
2 - 사용자가 텍스트를 입력하고 Enter 키를 누르면 코어 데이터에 저장됩니다.
제 문제는 어떻게 숫자 1을 수행 할 수 있습니다, 데이터가로드되지 않았기 때문에로드 할 수 없습니다. 데이터가 없으므로! 먼저 셀을 표시해야합니다.
누구든지이 문제에 대해 도움을 줄 수 있습니까? 여기에 무엇이 누락되어 있는지 이해해주십시오. 이것은 지금까지 내 코드입니다 : 그는 채울 수 있도록
이- (void)viewDidLoad
{
AppDelegate *appDelegate =[[UIApplication sharedApplication] delegate];
self.managedObjectContext=[appDelegate managedObjectContext];
NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
[self fetchedResultsController];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"machines";
cellMeios *cellM = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellM == nil) {
cellM = [[cellMeios alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cellM;
}
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil)
{
return _fetchedResultsController;
}
// Create and configure a fetch request.
NSFetchRequest *fetchRequestMo = [[NSFetchRequest alloc] init];
NSEntityDescription *entityMo = [NSEntityDescription entityForName:@"Mo" inManagedObjectContext:self.managedObjectContext];
[fetchRequestMo setEntity:entityMo];
// Create the sort descriptors array.
NSSortDescriptor *cellTitle = [[NSSortDescriptor alloc] initWithKey:@"reference" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:cellTitle, nil];
[fetchRequestMo setSortDescriptors:sortDescriptors];
// Create and initialize the fetch results controller.
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequestMo managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"reference" cacheName:nil];
_fetchedResultsController.delegate = self;
self.fetchedResultsController = _fetchedResultsController;
return _fetchedResultsController;
}
가 다른 방법이 있지만 나는 그들이 내 문제와 관련이 없습니다 생각, 물건은 ... 내가 사용자에게 무언가를 표시해야 !
이미 코어 데이터를 사용하는 다른 tableview가 있습니다.하지만이 경우 테이블은 우선 비어 있어야합니다. 그리고 나서 tableview 맨 위에 plus 버튼이 있습니다. 그러면 그는 뭔가를 선택하고 get's합니다. 관련 정보가있는 셀을 표시하는 코어 데이터에 저장됩니다.
미리 감사드립니다. 감사합니다.
안녕하세요 스티븐, 우선 정말이 하나 붙어 미안, 내 게시물에 응답 해 주셔서 감사합니다. 당신은 이렇게 말합니다 : "fetchedResultsController가 다시 비어있는 경우에도이 메소드를 트리거 할 수 있습니다"... 어떻게 수행 할 수 있습니까? 내 세포를 바로 참조해야합니까? 내가하고 싶은 것은 최선의 접근 방식인가? – Japa
본질적으로 사용자가 편집 할 항목이 있으면 개체가 이미 있어야 편집 한 것입니다. 이 메소드는 모델 및 테이블에 새 오브젝트를 삽입하여 하나 이상의 항목을 포함하는 예제입니다. NSFetchedResultsControllerDelegate 메소드 인 controllerDidChangeContent :를 구현하면 뷰 컨트롤러에서 가져 오기가 완료 될 때 호출됩니다. 그런 다음 가져 오기에서 결과가 반환되지 않으면 insertNewObject를 직접 호출하십시오. 이렇게하면 새 객체가있는 표가 다시로드됩니다. 화면에 무엇인가 나타나기 전에 가능성이 높습니다. –