こんにちは私は、iOS 4.3.3で、ダウンロードされたXcode 4.2.1とiOS sdk 5よりもアプリを作成しました。これはナビゲーションベースのアプリケーションで、tableviewの可変配列を持っています配列の文字列を作成しないでください。オブジェクトをviewdidloadの配列に追加しましたが、動作しません!だから、私の配列内のオブジェクトにNSlogを追加し、nullと言う!私は何をすべきか?ここでiOS 5 sdkの変更可能な配列の問題
は、のviewDidLoadです:
- (void)viewDidLoad
{
[super viewDidLoad];
self.soldc = [NSMutableArray arrayWithCapacity:0];
self.color = [NSMutableArray arrayWithCapacity:0];
appdelegate = (yard_sale_managerAppDelegate *)[[UIApplication sharedApplication] delegate];
appdelegate.object = self;
NSMutableArray *loadi = [[NSMutableArray alloc]initWithCapacity:0];
self.items = loadi;
self.sold = [NSMutableArray arrayWithCapacity:0];
self.prices = [NSMutableArray arrayWithCapacity:0];
alert = [[UIAlertView alloc] initWithTitle:@"Add product" message:@"Enter your product name and price." delegate:self cancelButtonTitle:@"Add" otherButtonTitles:@"Cancel", nil];
[alert addTextFieldWithValue:@"" label:@"name"];
[alert addTextFieldWithValue:@"" label:@"price"];
add = [alert textFieldAtIndex:0];
add.keyboardType = UIKeyboardTypeAlphabet;
add.keyboardAppearance = UIKeyboardAppearanceAlert;
add.autocapitalizationType = UITextAutocapitalizationTypeWords;
add.autocorrectionType = UITextAutocorrectionTypeNo;
add2 = [alert textFieldAtIndex:1];
add2.keyboardType = UIKeyboardTypeNumberPad;
add2.keyboardAppearance = UIKeyboardAppearanceAlert;
add2.autocapitalizationType = UITextAutocapitalizationTypeWords;
add2.autocorrectionType = UITextAutocorrectionTypeNo;
NSLog(@"%i", [color count]);
alert.tag=1;
self.resa = [[UIAlertView alloc] initWithTitle:@"Sale results" message:@"temple" delegate:self cancelButtonTitle:@"Close" otherButtonTitles: nil];
self.items = [NSMutableArray arrayWithContentsOfFile:[self itemsp]];
self.prices = [NSMutableArray arrayWithContentsOfFile:[self pricesp]];
self.sold = [NSMutableArray arrayWithContentsOfFile:[self soldp]];
self.soldc = [NSMutableArray arrayWithContentsOfFile:[self soldcp]];
self.color = [NSMutableArray arrayWithContentsOfFile:[self colorsp]];
if ([self.soldc count]==0) {
}
//self.soldc = [NSMutableArray arrayWithContentsOfFile:[self soldcp]];
self.color = [NSMutableArray arrayWithContentsOfFile:[self colorsp]];
[loadi release];
self.resa.tag = 2;
[self.items addObject:@"chair"];
[self.prices addObject:@"30"];
[self.color addObject:@"0"];
NSLog(@"%@",self.items);
}
あなたが私に言うより多くの情報が必要な場合は! これはログです:
2012-01-08 21:31:13.409 yard sale manager[1152:f803] 0
2012-01-08 21:31:13.411 yard sale manager[1152:f803] (null)
編集:その重要これを読ん!!!!! 多くの人がそのコードに気付かなかった: [self.items addObject:@ "chair"];
[self.prices addObject:@ "30"]; [self.color addObject:@ "0"]; NSLog(@ "%@"、self.items);
あなたは、あなたがしていることをかなり控えめに考えているわけではありません。 'viewDidLoad'の最後にフィールドを更新するのは何が良いのでしょうか?そして、あなたは 'arrayWithContentsOfFile'がnilを返すことができると思いますか? itemsp { NSStringの*パス= [NSStringのstringWithFormat(NSStringの*) - :@ "%@%@"、[[NSBundle mainBundle] resourcePath]、@ –