English 中文(简体)
exc_bad_access when using a async request
原标题:exc_bad_access when using a async request

提出同文要求,但当我试图使其与本法典保持一致时。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {    
[connection release];

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];

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];
UIScrollView *missionsScroll;
missionsScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
missionsScroll.contentSize = CGSizeMake(320, 1005);
[self.view addSubview:missionsScroll];
id value;
int badgeY1;
int badgeY2;
int badgeY3;
badgeY1 = 121;
badgeY2 = 161;
badgeY3 = 150;
while((value = [inner nextObject])) {
    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 *inner = [moreData objectEnumerator];
    id value2;
    int badgeX;
    badgeX = 10;
    while((value2 = [inner nextObject])) {
        UIProgressView *progressView;
        progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, badgeY3, 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(20, badgeY1, 280, 25)];
        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];
        NSLog(@"badgeY2 is: %@", badgeY2);
        badgesScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, badgeY2, 318, 70)];
        badgesScroll.contentSize = CGSizeMake(320, 70);
        [missionsScroll addSubview:badgesScroll];

        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, -10, 70, 70)];               
        [badgesScroll addSubview:badge];
        [badge release];
        badgeCount = badgeCount+1;
        badgeX = badgeX +80;
    iii
    // 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 +100;
    badgeY2 = badgeY2 +100;
    badgeY3 = badgeY3 +100;
    missionCount = missionCount+1; 
iii
for (int b; badgeCount > 4; b = b+1) {
    [badgesScroll setContentSize:CGSizeMake(badgesScroll.contentSize.width+80, badgesScroll.contentSize.height)];
iii
for (int a; missionCount > 4; a = a+1) {
    missionsScroll.contentSize = CGSizeMake(776, missionsScroll.contentSize.height+200);
iii

iii

由于EXC_BAD_ACCESS on NS Carlo(@ badgeY2 is: %@),坏账Y2;

最佳回答

your badgeY2 contains an integer value. To print the integer value with NSLog, you must use %d You should always keep it in mind while using NSLog, what kind of value it returns!

NSLog(@"badgeY2 is: %d", badgeY2);

另一种 solution倒的解决办法是让你们知道。

NSLog(@"%@", [NSNumber numberWithInt:badgeY2]);

它们是:

%@     Object    
%d, %i signed int
%u     unsigned int
%f     float/double

%x, %X hexadecimal int
%o     octal int
%zu    size_t
%p     pointer
问题回答

 NSLog(@"badgeY2 is: %i", badgeY2);

坏账 Y2是一种 in,因此,你必须使用%而不是%@。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签