我試圖將元素添加到使用此代碼滾動視圖:對象沒有顯示出來
int missionCount;
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *missionsDict = [responseString JSONValue];
/*NSArray *luckyNumbers = [json objectWithString:responseString error:&error];*/
NSLog(@"user Info array is: %@", missionsDict);
// NSDictionary *array = [luckyNumbers1 objectForKey:@"data"];
NSDictionary *missionsData;
missionsData = [missionsDict objectForKey:@"data"];
NSLog(@"missionsData is: %@", missionsData);
NSEnumerator *inner = [missionsData objectEnumerator];
missionsScroll.contentSize = CGSizeMake(768, 1005);
id value;
int badgeY1;
int badgeY2;
int badgeY3;
badgeY1 = 146;
badgeY2 = 188;
badgeY3 = 188;
while((value = [inner nextObject])) {
NSLog(@"value is: %@", value);
NSLog(@"progress is: %@", [value objectForKey:@"progress"]);
NSLog(@"user Info array is: %@", missionsDict);
NSLog(@"name is: %@",[value objectForKey:@"reward_definitions"]);
NSLog(@"missionsData is: %@", missionsData);
NSDictionary *moreData;
moreData = [value objectForKey:@"reward_definitions"];
NSEnumerator *inner2 = [moreData objectEnumerator];
id value2;
int badgeX;
int badgeCount;
badgeX = 0;
badgeCount = 0;
while((value2 = [inner2 nextObject])) {
UIProgressView *progressView;
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(323, badgeY1, 372, 9)];
float progressValue;
progressValue = ([[[value objectForKey:@"progress"] objectForKey:@"earned"] floatValue]/[[[value objectForKey:@"progress"] objectForKey:@"possible"] floatValue]);
NSLog(@"progressValue is: %f", progressValue);
[progressView setProgress:progressValue];
[missionsScroll addSubview:progressView];
UILabel *missionName;
missionName = [[UILabel alloc] initWithFrame:CGRectMake(66, badgeY1, 227, 21)];
missionName.backgroundColor = [UIColor clearColor];
missionName.textColor = [UIColor whiteColor];
missionName.font = [UIFont fontWithName:@"Heiti TC" size:23.0];
missionName.text = [value objectForKey:@"name"];
[missionsScroll addSubview:missionName];
UILabel *requirementsLabel;
requirementsLabel = [[UILabel alloc] initWithFrame:CGRectMake(66, badgeY2+25, 227, 21)];
requirementsLabel.backgroundColor = [UIColor clearColor];
requirementsLabel.textColor = [UIColor whiteColor];
requirementsLabel.font = [UIFont fontWithName:@"Papyrus" size:19];
requirementsLabel.text = @"To complete you need:";
[missionsScroll addSubview:requirementsLabel];
NSLog(@"Image URL is: %@", [value2 objectForKey:@"image_url"]);
NSURL *url1 = [NSURL URLWithString: [NSString stringWithFormat:@"%@", [value2 objectForKey:@"image_url"]]];
NSData *urlData1 = [NSData dataWithContentsOfURL:url1];
UIImage *image1 = [UIImage imageWithData:urlData1];
UIImageView *badge = [[UIImageView alloc] initWithImage:image1];
[badge setFrame:CGRectMake(badgeX, badgeY2+70, 70, 70)];
[missionsScroll addSubview:badge];
[badge release];
badgeCount = badgeCount+1;
NSLog(@"badgeCount is: %i", badgeCount);
if (badgeCount == 4) {
NSLog(@"Badge Count = 4");
badgeY2 = badgeY2 +70;
badgeX = 0;
badgeCount = 0;
} else {
NSLog(@"Badge Count ≠ 4");
badgeX = badgeX +75;
}
}
NSLog(@"1st While loop done");
// NSLog(@"reward_definitions is: %@", [missionsData objectForKey:@"id"]);
// NSLog(@"Image URL is: %@", [[value objectForKey:@"reward_definitions"] objectForKey:@"image_url"]);
//if ([array isKindOfClass:[NSDictionary class]]) {
badgeY1 = badgeY1 +200;
badgeY2 = badgeY2 +200;
badgeY3 = badgeY3 +200;
missionCount = missionCount+1;
}
NSLog(@"While loops done");
for (int a; missionCount > 4; a = a+1) {
missionsScroll.contentSize = CGSizeMake(776, missionsScroll.contentSize.height+200);
}
什麼也不表示在滾動視圖向上。
這也將是一個很好的想法來驗證視圖的幀在超視圖內。 – NWCoder