【发布时间】:2012-01-08 19:47:49
【问题描述】:
您好,我在 iOS 4.3.3 上创建了一个应用程序,然后下载了 Xcode 4.2.1 和 iOS sdk 5。它是一个基于导航的应用程序,它有一个用于 tableview 的可变数组,但它不会为数组,所以我在 viewdidload 的数组中添加了一个对象,但它不起作用!所以我将 NSlog 添加到我的数组中的对象中,它显示为空!我该怎么办?
这里是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吗?
标签: iphone objective-c ios ios5 xcode4.2