こんにちは友人を空の配列を返すと、私は新しいit..Iがcoredataの公式ドキュメントを読んで、それで遊ぶことを試みています私が書いている、私がしたので、何...</p> <p>をcoreDataに、私はcoreDataで働いています
1.Iは、最初に作成の手順は... coredataオプション付きwindowbasedプロジェクトが
2.Iは、「従業員」と3 attributes..a)名B)部門c)はxcdatamodeldを開き、名前であるエンティティを追加選択しました指定。
3.私はemployee.hを作成しました。 employee.m
4.Nowは私FirstTableViewController.m に私はこのコード
- (void)viewDidLoad
{
[super viewDidLoad];
Employee *emp = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:managedObjectContext];
Employee *emp1 = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:managedObjectContext];
m_employeeArray = [[NSMutableArray alloc]init];
[emp setName:@"Jack"];
[emp setDept:@"Accounts"];
[emp setDesignation:@"Manager"];
[emp1 setName:@"Joseph"];
[emp1 setDept:@"Finance"];
[emp1 setDesignation:@"Manager"];
[m_employeeArray addObject:emp];
[m_employeeArray addObject:emp1];
//Code to save the data..
NSError *error = nil;
if (![managedObjectContext save:&error]) {
// Handle the error.
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
m_mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error]mutableCopy];
if (m_mutableFetchResults == nil) {
// Handle the error.
}
for (Employee *info in m_mutableFetchResults)
{
NSLog(@"Name: %@", emp.Name);
NSLog(@"Name: %@", emp.Dept);
NSLog(@"Name: %@", emp.Designation);
}
}
を書いて、私のtabelのデリゲートメソッドは
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [m_employeeArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
Employee *emp = (Employee *)[m_employeeArray objectAtIndex:indexPath.row];
cell.textLabel.text = emp.Name;
return cell;
}
とだから私は私が手にビューをロード下回っていますセルは2つの名前、すなわちJackとJosephで埋められています ここで私はm_mutableFetchResultsにデータを保存し、コンソールに出力を表示していて、プロジェクトが実行されるたびにデータが保存され、正常に動作していることがわかります。
は今、私はそう下記m_mutableFetchResults
で満たさsecondTableViewControllerは私
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
SecondTableViewController *detailViewController = [[SecondTableViewController alloc] initWithNibName:@"SecondTableViewController" bundle:nil];
[detailViewController setSavedArray:m_mutableFetchResults];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
と私はsecondTableViewControllerを充填していているが表示されますので、FirstTableViewControllerのdidselectrowにSecondTableViewController
と呼ばれる別のtableviewcontrollerを作成しました[savedArray count]で、secondTableViewControllerの配列は空です。私はどこが間違っているのか理解していません...
友人たち、私はあなたにすべて私の問題を理解させるように努力しました...
私を助けてください。
こんにちは、あなたの返信ありがとう、ViewDidLoadメソッドでseconviewTableViewcontrollerで私は最初にsavedarrayを初期化し、次に 私はそれをテーブルデリゲートメソッドで使用しました。 – Ranjit
こんにちは友人、私を助けてください – Ranjit