2012-04-19 12 views
-1

私は、Intとして宣言されたplaceIdを持つPlacesというクラスを持っています。乱数を返すXcode int

int placeId; 

私は場所がその配列にオブジェクトを格納するためのArrayListを作成し、私のplaceIdを返す方法/

- (int) getPlaceId; 

- (int)getPlaceId{ 
return placeId; 
} 

を持っています。 私のplaceIDを取得するメソッドを実行すると、私は奇妙な数字の範囲を戻っているようです。例えば。 1234567.

これはなぜ起こっているのですか?

NSString *tempInt = [tempObject objectForKey:@"placeId"]; 
    NSString *tempString = [tempObject objectForKey:@"name"]; //2 

    //convert temptInt to integer 
    NSInteger myInt = (NSInteger)tempInt; 

    Places *p = [[Places alloc]set:myInt andb:tempString]; 
    [del.delegateArrayPlaces addObject:p]; 

ここに私が追加する方法はありますか?他のコードは何ですか?

+0

あなたは私たちにあなたが配列を作成したコードを示してもらえますか? –

+0

'NSString *'を 'NSInteger'にキャストしますか?それはどのように働くでしょうか? – trojanfoe

+0

@trojanfoe申し訳ありません、私はXCodeを開始しました。 – Hexark

答えて

1

あなたのコードのどこかに整数ivar getが実際にポインタに割り当てられ、これがあなたのものです。 は私たちにあなた

編集(コードを掲示した後)を支援するためにいくつかのコードを表示:

NSString *tempString = [tempObject objectForKey:@"name"]; //2 

//convert temptInt to integer 
NSInteger myInt = [tempString intValue];