CoreData 객체에서 정보를 가져 오는이 tableview에서 작업하는 경우, CoreData에 객체를 추가하려고 할 때 tableview가 작동하지 않으면이 객체를 애니메이션으로 만들겠습니다. CoreDataBase (코어 데이터 방법)에서CoreData에서 셀이 삽입되지 않음
:이 임하려는 것입니다
+(void)insertNewTask:(NSString *) task
withnote:(NSString *) note
withnotDate:(NSDate *) notdate{
[MagicalRecord saveUsingCurrentThreadContextWithBlock:^(NSManagedObjectContext *localContext) {
Task *thetask = [Task MR_createEntity];
thetask.task = task;
thetask.note = note;
thetask.date = [NSDate date];
thetask.notdate = notdate;
} completion:^(BOOL success, NSError *error) {
NSLog(@"Accounts:%d", [CoreDataBase numberofTasks]);
}];
}
을 그리고 텍스트 필드에서 돌아 오는 때있는 tableview 컨트롤러에 업데이트가 발생, 텍스트는 supose 인 하나입니다 tableview와 coredata에 추가 될 것입니다 (테이블을 다시 열면 모든 객체를 볼 수 있기 때문에 coredata에 추가됩니다) :
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
NSDate *date = [NSDate dateWithTimeIntervalSince1970:1];
[CoreDataBase insertNewTask:textField.text withnote:textField.text withnotDate:date];
[self reloadCards];
textField.text = @"";
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:(0) inSection:0];
[self.tableview beginUpdates];
[self.tableview insertRowsAtIndexPaths:[NSArray arrayWithObject:[self keyForIndexPath:newIndexPath]] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableview endUpdates];
[textField addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:NULL];
[textField resignFirstResponder];
[CoreDataBase logAllTasks];
return YES;
}
-(void)reloadCards{
self.allTasks = [[CoreDataBase allTasksWithDateSort:NO] mutableCopy];
[self.tableview reloadData];
}
그리고 이것은 (난 단지로드에서 다시 열기 말했듯이 아닌 텍스트 필드의 반환에) 나는 테이블에 정보를 표시하는 방법입니다
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
MCSwipeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.delegate = self;
[tableView setRowHeight:73];
Task *task = self.allTasks[indexPath.row];
cell.taskTitle.text = [task task];
}
그래서 내가 잘 설명 바랍니다 내 문제, MagicalRecord와 함께 일하는 Im 그래서 행 수를 세는 방법과 복잡하지 않은 것은 모두 내가 그 (것)들을 게시하지 말고 고마워하고 당신이 나를 도울 것입니다.
가장 좋은 건 'NSFetchedResultsController'를 사용하는 것입니다. 여기에 몇 가지 토론이 있습니다 https://github.com/magicalpanda/MagicalRecord/issues/404 –
안녕하세요, 너무 많이 물어 보지 않으시다면 어떻게 대답 할 수 있습니까? 고맙습니다 –