ああ、私は本当にこの1つのピクルスにいます。たぶんあなたの新鮮な目はいくつかの魔法をすることができます..iPhoneのコアデータ - NSNumberとobj_exception_throwに関する問題
私のアプリはviewDidLoadでこの行を取得するとクラッシュします。
NSString *fieldName = [NSString stringWithFormat:@"position%d", [objectPosition intValue]];
私はそれが原因それを上回っている。このラインにあるかもしれないと思う:
NSNumber *objectPosition = [[object position] integerValue];
fieldNameをライン上の明示的なエラーはありません。
一般的な警告が含まれます:
初期化キャスト
なし整数からポインタを作る 'NSManagedObjectは' '位' に
obj_exception_throw
クラスをチェックしました[オブジェクトの位置]と、実際にはNSCFNumberだと言います。 NSNumberに問題がありますか?どこが間違っていますか?
おかげ
進化
全体の方法がここに記載されている、ここにもNSInteger
、ないNSNumber *
を返しますファイル全体https://gist.github.com/801879
- (void)viewDidLoad {
// Format page
scrollView.contentSize = CGSizeMake(200, 430);
// Initialise PositionsView array
positionViews = [[NSArray alloc] initWithObjects:position1,position2,position3,position4,position5,position6,position7,position8,position9,position10,position11,position12,position13,position14,position15,position16,position17,position18,nil];
// Load managedObject
//Fetch All players from PlayerPosition where game matches this game and store in objects
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"PlayerPosition" inManagedObjectContext:managedObjectContext_];
[request setEntity:entityDescription];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(game = %@)", self.game]; //WHERE game = self.game
[request setPredicate:pred];
NSError *error;
objects = [managedObjectContext_ executeFetchRequest:request error:&error]; //execute fetch and store in objects
NSLog(@">>>>>>>>>>>>>>>>>>>>>>>>>> Populate View with data from the managedObject.. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
for (NSManagedObject *object in objects) {
//loop through the objects in PlayerPosition for this game and update UI elements.
Player *objectPlayer = [object valueForKey:@"player"];
NSNumber *objectPosition = [[object position] integerValue];
NSLog(@"Object: %@", [object valueForKey:@"position"]);
NSString *fieldName = [NSString stringWithFormat:@"position%d", [objectPosition intValue]];
PlayerPositionView *theField = [self valueForKey:fieldName];
[[theField textLabel] setText:objectPlayer.playerShortName];
NSLog(@"object Position: %@", [objectPosition description]);
}
NSLog(@">>>>>>>>>>>>>>>>>>>>>>>>>> ..view Data Loaded <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
[super viewDidLoad];
}
Iveに変更があります。それが少し助けてくれたと思います。私はこのページに今私のアプリでは、クラッシュせずに取得することができます、レコードを追加して終了して戻ってくると、 '変数にアクセスできませんでした'という同じ行の文句を言う "fieldName" – Evolve