2015-04-04 51 views
-2

長時間運行的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]; 

回答

1

代碼這可能是這樣的:

[[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]] 

你看上去同步獲取圖像,而不是異步。

而不是使用UIImageView,您應該使用PFImageView,它將異步下載該文件,如果它尚未被緩存。

+0

試過,我得到錯誤未知的接收器 – 2015-04-04 18:08:42

+0

好吧添加了一個標題...改爲PFImageView,仍然得到警告 – 2015-04-04 18:45:07

相關問題