간단한 데이터이지만 문제를 찾을 수없는 것 같습니다. 새로운 요소가 데이터베이스에 추가되지 않고 코드에서 오류가 발생하지 않습니다. 여기 iPhone 코어 데이터를 추가 할 때
은 추가 그것이 사용자 mpmediapicker에서 노래를 집어 들고 다른보기 제어기에 메시지를 전송 호출 된 후 추가 방법- (void) addPressed:(NSNotification *) message
{
// Insert a new record in the database
Track *track2 = [NSEntityDescription insertNewObjectForEntityForName: @"Track" inManagedObjectContext: managedObjectContext];
[managedObjectContext save: &error];
tracks = [self fetchTracks];
// Insert a new item in the table's data source
[tracks insertObject: track2 atIndex: 0];
// Insert a new row in the table
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection: 0];
addTrack.track = [tracks objectAtIndex: indexPath.row];
NSLog(@"here");
[[NSNotificationCenter defaultCenter] postNotificationName:@"choosePressed" object:self];
}
된 후,이 방법
- (void) finishedEditing
{
if(start.text.length == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Warning" message: @"You must fill out all fields" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
alert.tag = 1;
[alert show];
[alert release];
}
else if(duration.text.length == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Warning" message: @"You must fill out all fields" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
alert.tag = 1;
[alert show];
[alert release];
}
else if(name.text.length == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Warning" message: @"You must fill out all fields" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
alert.tag = 1;
[alert show];
[alert release];
}
else if(songLabel.text.length == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Warning" message: @"You must select a song" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
alert.tag = 1;
[alert show];
[alert release];
}
else
{
if (repeat)
{
track.title = NULL;
track.name = NULL;
repeat = NO;
}
else
{
songLabel.text = @"";
artistLabel.text = @"";
[self viewWillDisappear: YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
track.name = name.text;
track.duration = duration.text;
track.startloc = start.text;
track.title = [song valueForProperty:MPMediaItemPropertyTitle];
NSManagedObjectContext *context = track.managedObjectContext;
NSError *error = nil;
[context save: &error];
[[NSNotificationCenter defaultCenter] postNotificationName:@"myTraxsTab" object:self];
}
}
}
를 선택하는 저장 버튼을 안타
가져온 결과 컨트롤러가 아닌 NSFetchRequest를 사용하고 있습니다. 코드를 heres.
request = [[NSFetchRequest alloc] init];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES];
sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
request.sortDescriptors = sortDescriptors;
[sortDescriptor release];
error = nil;
entity = [NSEntityDescription entityForName: @"Track" inManagedObjectContext: managedObjectContext];
request.entity = entity;
UPDATE
좋아, 그래서 여기에 다른 문에
else
{
songLabel.text = @"";
artistLabel.text = @"";
[self viewWillDisappear: YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
track.name = name.text;
track.duration = duration.text;
track.startloc = start.text;
track.title = [song valueForProperty:MPMediaItemPropertyTitle];
NSManagedObjectContext *context = track.managedObjectContext;
NSError *error = nil;
[context save: &error];
NSLog(@"array: %@", tracks);
[[NSNotificationCenter defaultCenter] postNotificationName:@"myTraxsTab" object:self];
}
를 배열을 인쇄 한 줄을 추가 그리고 이것은 인쇄입니다 것입니다. 나는 실종 된 게 뭔지 모르겠다. 그게 날 미친 짓이야. 그리고 분명히 이름, 기간 및 시작 레이블에 값을 추가했습니다.
array: (
"<Track: 0x136d80> (entity: Track; id: 0x13a120 <x-coredata://9D789618-64C1-40BF-9F15-BA6A3EA715D3/Track/p7> ; data: {\n duration = nil;\n name = nil;\n startloc = nil;\n title = nil;\n})"
)
데이터 모델을 게시 할 수 있습니까? 텍스트는 괜찮습니다. 너무 성가신 경우 화면을 캡쳐하십시오. 나는 당신이 tableViewController에 연결된 fetchedResultsController를 가지고 있다고 가정합니다. - 그 경우입니까? 그렇지 않다면 우리는 거기에서 시작할 필요가 있습니다 :-) –
NS fetchedResults 컨트롤러가 아니라 NSFetchRequest를 사용하고 있습니다. 코드를 heres. request = [[NSFetchRequest alloc] init]; NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey : @ "name"오름차순 : YES]; sortDescriptors = [[NSArray alloc] initWithObjects : sortDescriptor, nil]; request.sortDescriptors = sortDescriptors; [sortDescriptor release]; 오류 = nil; entity = [NSEntityDescription entityForName : @ManagedObjectContext의 "Track": managedObjectContext]; request.entity = 엔티티; – user1034642
저장하지 않는다는 것을 어떻게 알 수 있습니까? 새 항목이 테이블에 나타나지 않기 때문에? 'sqlite3' 명령 줄 도구 또는 다른 SQLite 데이터베이스 브라우저로 확인 했습니까? – Mundi