2014-12-30 2 views
0

주 스레드에서 실행중인 Parse 연산이 아래에서이 코드 부분에서 일어나고 있습니다. 오류 제거 방법을 찾을 수없는 것 같습니다. 경고를 없애는 방법에 대한 도움. 여기 장기 실행 구문 분석 작업이 주 스레드에서 실행되고 있습니까?

PFFile *image = (PFFile *)[wallObject objectForKey:KEY_IMAGE]; 
UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]]; 
userImage.frame = CGRectMake(0, 65, wallImageView.frame.size.width, 225); 
[wallImageView addSubview:userImage]; 

는 먼저 데이터를 사용할 수 있는지 확인해야합니다

-(void)loadWallViews 
{ 
    //Clean the scroll view 
    for (id viewToRemove in [self.wallScroll subviews]){ 

     if ([viewToRemove isMemberOfClass:[UIView class]]) 
      [viewToRemove removeFromSuperview]; 
    } 

    //For every wall element, put a view in the scroll 
    int originY = 10; 

    for (PFObject *wallObject in self.imageFilesArray){ 

     //Build the view with the image and the comments 
     UIView *wallImageView = [[UIView alloc] initWithFrame:CGRectMake(10, originY, self.view.frame.size.width - 20 , 330)]; //self.view.frame.size.height 
     //[[UIView appearance] setBackgroundColor:[UIColor redColor]]; //added for problem solve 

     //Add the image 
     PFFile *image = (PFFile *)[wallObject objectForKey:KEY_IMAGE]; 

     UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]]; 
     userImage.frame = CGRectMake(0, 65, wallImageView.frame.size.width, 225); 
     [wallImageView addSubview:userImage]; 

     UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, wallImageView.frame.size.width,55)]; 
     infoLabel.text = [wallObject objectForKey:@"newsTitle"]; 
     infoLabel.font = [UIFont fontWithName:KEY_FONT size:20]; 
     infoLabel.textColor = [UIColor darkGrayColor]; 
     infoLabel.backgroundColor = [UIColor clearColor]; 
     infoLabel.numberOfLines = 0; 
     [wallImageView addSubview:infoLabel]; 

     //Add the info label (User and creation date) 
     NSDate *creationDate = wallObject.createdAt; 
     NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
     [df setDateFormat:KEY_DATEFORMAT]; 

     //Add the comment 
     UILabel *commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, wallImageView.frame.size.width, 12)]; 
     //commentLabel.text = [NSString stringWithFormat:@"Uploaded by: %@, %@", [wallObject objectForKey:@"NewsDetail"], [df stringFromDate:creationDate]]; 
     commentLabel.text = [NSString stringWithFormat:@": %@, %@", [wallObject objectForKey:@"newsDetail"], [df stringFromDate:creationDate]]; 
     commentLabel.font = [UIFont fontWithName:KEY_FONT size:10]; 
     commentLabel.textColor = [UIColor lightGrayColor]; 
     commentLabel.backgroundColor = [UIColor clearColor]; 
     [wallImageView addSubview:commentLabel]; 

     UILabel *readLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 71 , 50, wallImageView.frame.size.width, 12)]; 
     readLabel.text = @"Read more"; 
     readLabel.font = [UIFont fontWithName:KEY_FONT size:10]; 
     readLabel.textColor = [UIColor blueColor]; 
     readLabel.backgroundColor = [UIColor clearColor]; 
     [wallImageView addSubview:readLabel]; 

     UIButton *faceBtn = [[UIButton alloc] initWithFrame:CGRectMake(2,310, 20, 20)]; 
     [faceBtn setImage:[UIImage imageNamed:@"Facebook.png"] forState:UIControlStateNormal]; 
     [faceBtn addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside]; 
     [wallImageView addSubview:faceBtn]; 

     UIButton *twitBtn = [[UIButton alloc] initWithFrame:CGRectMake(32,310, 20, 20)]; 
     [twitBtn setImage:[UIImage imageNamed:@"Twitter.png"] forState:UIControlStateNormal]; 
     [twitBtn addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside]; 
     [wallImageView addSubview:twitBtn]; 

     UIButton *tumblrBtn = [[UIButton alloc] initWithFrame:CGRectMake(62,310, 20, 20)]; 
     [tumblrBtn setImage:[UIImage imageNamed:@"Tumblr.png"] forState:UIControlStateNormal]; 
     [tumblrBtn addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside]; 
     [wallImageView addSubview:tumblrBtn]; 

     UIButton *yourBtn = [[UIButton alloc] initWithFrame:CGRectMake(92,310, 20, 20)]; 
     [yourBtn setImage:[UIImage imageNamed:@"Flickr.png"] forState:UIControlStateNormal]; 
     [yourBtn addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside]; 
     [wallImageView addSubview:yourBtn]; 
    // wallImageView = UIEdgeInsetsMake(0.0f, myCell.frame.size.width, 0.0f, 400.0f); 
     UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 343, self.view.frame.size.width, .8)]; 
     separatorLineView.backgroundColor = [UIColor grayColor];// you can also put image here 
     [wallImageView addSubview:separatorLineView]; 

     [self.wallScroll addSubview:wallImageView]; 

     originY = originY + wallImageView.frame.size.width + 1; 

    } 

    //Set the bounds of the scroll 
    self.wallScroll.contentSize = CGSizeMake(self.wallScroll.frame.size.width, originY); 

    //Remove the activity indicator 
    [self.activityIndicator stopAnimating]; 
    [self.activityIndicator removeFromSuperview]; 
} 
+0

오류 또는 오류? – TooManyEduardos

+0

Peter는 상징적 인 중단 점을 만들면 범죄자가 될 수 있습니다. – soulshined

답변

0

아래의 코드이며, 만약 그렇다면, 그것을 사용하고, 그렇지 않은 경우를 검색 할 수 있습니다. 이 작업이 길다는 경고를 받게됩니다 (PFFile에 엄청난 양의 데이터가있는 경우 일 수 있음).하지만 안전합니다. 블록을 사용하여 네트워크를 통해서만 데이터를 검색한다면 괜찮을 것입니다.

// PFFile *imageFile 
UIImage *image; 
if ([imageFile isDataAvailable]) { 
    image = [UIImage imageWithData:[imageFile getData]]; 
} else { 
    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
     if (error) { 
      // error 
     } else { 
      if (data != nil) { 
       image = [UIImage imageWithData:data]; 
      } 
     } 
    }]; 
} 

은 PFFile에 대한 데이터를 검색에 블록 싶지 당신이 무엇. PFFile에서 데이터를 사용할 수 있다면 블록없이 getData를 안전하게 호출 할 수 있습니다.

관련 문제