もう一つの初心者の質問です。私はiosプログラミングで非常に の小さなハンドルを取得し始めていると思っていました。うん!私は、 appcodeblog.comのtutoriaに従っています。 コアデータを利用して休暇先を入力、表示、検索する簡単なタブバーアプリケーションを構築しています。私はチュートリアルを通して を働いて、動作するアプリケーションを持っていましたが、私が "目的地を表示"タブを選択すると、次のエラーが表示されます。アプリは続行しているようですが、エラーはコンソールに記録されます。 の問題をデバッグしようとしていて、何が起こっているのかを正確に理解しようとしていますが、ちょうどあてになっていません。 何が間違っているのかを理解してください。私は ShowDestinations.xibファイルに問題があります。ここでは、私が間違ってオブジェクトをxibに接続していました。どんな助けでも大変感謝しています。お返事ありがとうございました。 時間。ここで NSManagedObjectクラスで指定された初期化子を呼び出すことができませんでした
はエラー、「CoreDataTabBarTutorialです。[1262:207] NSManagedObjectクラスのデスティネーション」に関する指定 初期化子を呼び出すことができませんでした私は示すことによって、私が出始めてきたので、提供するためにどのようなコードわからないんだけど、私のヘッダ と実装ファイルShowDistinationsViewController.hと ShowDestinationsViewController.m
ShowDistinationsViewController.h
#import <UIKit/UIKit.h>
@interface SearchDestinationsViewController : UIViewController {
UISearchBar *destinationSearchBar;
UITableView *searchTableView;
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
NSArray *fetchedObjects;
}
@property (nonatomic, retain) IBOutlet UISearchBar *destinationSearchBar;
@property (nonatomic, retain) IBOutlet UITableView *searchTableView;
@property (nonatomic, retain) IBOutlet NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) IBOutlet NSManagedObjectContext *managedObjectContext;
@end
ShowDestinationsViewController.m
#import "ShowDestinationsViewController.h"
#import "Destination.h"
@implementation ShowDestinationsViewController
@synthesize destinationsTableView;
@synthesize destinationsArray;
@synthesize fetchedResultsController;
@synthesize managedObjectContext;
// Not sure where the following code came from so I commented it out!!! It didn't seem to break anything when I commented it out
//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
// self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
// if (self) {
// // Custom initialization
// }
// return self;
//}
- (void)dealloc
{
[destinationsArray release];
[destinationsTableView release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark -
#pragma Data Fetch from Core Data
- (void) viewWillAppear:(BOOL)animated
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Destination" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil)
{
// Handle the error.
NSLog(@"mutableFetchResults == nil");
}
[self setDestinationsArray:mutableFetchResults];
[request release];
[destinationsTableView reloadData];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [destinationsArray count];
}
// Customize the appearance of table view cells.
- (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...
Destination *destination = [[Destination alloc] init];
destination = (Destination *)[destinationsArray objectAtIndex:indexPath.row];
cell.textLabel.text = destination.name;
[destination release];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end
問題の原因と思われる 'Destination.h、.m'を投稿してください。 – Yuji
私は問題を見つけたと思う。投稿する必要はありません。 – Yuji
@ 5lb Bass [関連するNSManagedObjectContextなしでNSManagedObjectサブクラスをインスタンス化することはできません](http://stackoverflow.com/questions/1556304/cocoa-touch-nsmanagedobject-exception-when-setting-a-property/1556370#1556370 ) – albertamg