안녕하세요. iOS 4.3.3 및 다운로드 한 Xcode 4.2.1 및 iOS SDK 5보다 더 나은 앱을 만들었습니다. 탐색 기반 응용 프로그램이며 tableview에 대한 가변 배열이 있습니다. 배열에 대한 문자열을 만들지 않아서 viewdidload에 배열에 객체를 추가했지만 작동하지 않습니다! 그래서 배열에있는 객체에 NSlog를 추가했는데 null이라고 말합니다! 어떻게해야합니까?iOS 5 SDK 코드 변경 가능 어레이
- (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);
}
이 더 필요하면 정보를 말해 :
는 여기에있는 viewDidLoad입니다!
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을 리턴 할 수 있다는 것을 알고 있습니까? –