2013-07-22 5 views
0

다음보기를 사용하여 바로 다음 뷰로 전환하고 싶습니다. 아래의 방법을 사용하여 웹 서비스에서 데이터를 가져옵니다. 그러나 이것은 UITableView를 업데이트하지 않습니다.백그라운드에서 데이터를 가져 오지만 테이블 뷰가 업데이트되지 않음

// vewDidLoad 

[NSThread detachNewThreadSelector:@selector(setImage) toTarget:self withObject:nil]; 

-(void)setImage 
{  
      if([type isEqualToString:@"Organisation"]) 
      { 
       self.mGetDataDict = [MyEventApi members:self.mUserIdDict]; 
       self.mRecievedDataDict = [self.mGetDataDict valueForKey:@"members"]; 
      } 
      if([type isEqualToString:@"Individual"]){ 
       self.mGetDataDict = [MyEventApi friends:self.mUserIdDict]; 
       self.mRecievedDataDict = [self.mGetDataDict valueForKey:@"friends"]; 
      } 

      if([self.mGetDataDict valueForKey:@"friends"] == [NSNull null]) 
      { 
       UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"alert" message:@"You have not added any friend yet." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
       [alert show]; 
      } 
      else 
      { 
       self.mFrndNameArr = [[NSMutableArray alloc]init]; 
       self.mFrndImgArr = [[NSMutableArray alloc]init]; 
       self.mFirstNameArr = [[NSMutableArray alloc]init]; 
       self.mLastNameArr = [[NSMutableArray alloc]init]; 
       self.mFrndIdArr = [[NSMutableArray alloc]init]; 
       self.mFrndMSinceArr = [[NSMutableArray alloc]init]; 
       self.mFrndDescArr = [[NSMutableArray alloc]init]; 

       self.mFrndNameArr = [self.mRecievedDataDict valueForKey:@"username"]; 
       self.mFrndImgArr = [self.mRecievedDataDict valueForKey:@"image"]; 
       self.mFirstNameArr = [self.mRecievedDataDict valueForKey:@"firstName"]; 
       self.mLastNameArr = [self.mRecievedDataDict valueForKey:@"lastName"]; 
       self.mFrndIdArr = [self.mRecievedDataDict valueForKey:@"id"]; 
       self.mFrndMSinceArr = [self.mRecievedDataDict valueForKey:@"memberSince"]; 
       self.mFrndDescArr = [self.mRecievedDataDict valueForKey:@"description"]; 

       [self.mFriendsTable reloadData]; 
      }  
} 

아래는 cellForRowAtIndexPath 메소드입니다.

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell; 
     cell = [self.mFriendsTable dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    else{ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 

NSString *imageUrlString = [NSString stringWithFormat:@"http://www.myevent.co/%@",  [self.mFrndImgArr objectAtIndex:indexPath.row]]; 
[imageUrlString stringByReplacingOccurrencesOfString:@"/" withString:@""]; 

UILabel *lblEventName = [[UILabel alloc]initWithFrame:CGRectMake(92, 5, 200, 25)]; 
lblEventName.font = [UIFont fontWithName:@"Helvetica-Bold" size:14]; 
lblEventName.backgroundColor = [UIColor clearColor]; 
[cell.contentView addSubview:lblEventName]; 

if([copyArr count] >0) 
{ 
    lblEventName.text = [copyArr objectAtIndex:indexPath.row]; 
} 
else{ 
    lblEventName.text = [self.mFrndNameArr objectAtIndex:indexPath.row]; 
} 

asyncImageView = [[AsyncImageView alloc]initWithFrame:CGRectMake(1, 3, 85, 54)]; 
[asyncImageView loadImageFromURL:[NSURL URLWithString:imageUrlString]]; 
[cell.contentView addSubview:asyncImageView]; 

cell.textLabel.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0]; 
cell.contentView.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0]; 

return cell; 
} 

텍스트 데이터를 가져 오지만 테이블이 스크롤 될 때까지 이미지를 가져 오지 않습니다. 하지만이 방법을 사용하면 이미지도 표시되지만 모든 dat을 가져온 후에 다음 뷰로 전환됩니다.

// vewDidLoad 

[self setImage]; 

위의 지침을 따르십시오. 잘못된 스레드를 사용하는 방법이나 다른 방법 또는 방법을 사용해야합니다.

답변

0

는 별도의 스레드에서 데이터를 업데이트하기 때문에, 당신은 메인 스레드 자신이

[self.mFriendsTable reloadData]; 

사용이

[self.mFriendsTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; 
의 대신

에 다시로드를 실행해야

관련 문제