7

NSMutableArray があります

@interface DetailViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

NSMutableArray *reponses;
}
@property (nonatomic, retain) NSMutableArray *reponses;

@end

そして、配列 NSInteger オブジェクトに追加しようとしています:

@synthesize reponses;



NSInteger val2 = [indexPath row];
[reponses addObject:[NSNumber numberWithInteger:val2]];
NSLog(@"the array is %@ and the value is %i",reponses, val2);

オブジェクトが配列に追加されていないと機能しません。これがコンソールに表示されるものです。

the array is (null) and the value is 2
4

3 に答える 3

8

@Omz:そうです。アレイが割り当てられ、初期化されていることを確認してください。次のコードを確認してください

NSMutableArray *array = [[NSMutableArray alloc] init];
NSInteger num = 7;
NSNumber *number = [NSNumber numberWithInt:num];
[ar addObject:number];
NSLog(@"Array %@",array);

私はこれをチェックしました、そしてそれは働きます。array不要になった場合は、必ず確認してくださいrelease

于 2011-12-22T08:03:10.217 に答える
4

配列を初期化していないので、配列nilに追加しようとしているときです。

self.responses = [NSMutableArray array];
//now you can add to it.
于 2011-12-22T07:55:09.163 に答える
2

応答配列を初期化していません。あなたのコードでは、viewDidLoadかもしれませんが、次のようにします。

reponses = [[NSMutableArray alloc] init];

次に、オブジェクトを配列に追加します。

NSInteger val2 = [indexPath row];
[self.reponses addObject:[NSNumber numberWithInteger:val2]];

それはうまくいくはずです。

于 2011-12-22T07:58:47.550 に答える