2015-11-22 22 views
0

我想在我的tableview單元格中顯示從下面的AFNetworking調用接收到的responseObject。我在我的頭文件(neighbourData)中創建了一個NSMutableArray屬性,認爲爲它分配responseObject可能會起作用。雖然如預測,但我似乎無法使用AFNetworking方法之外的數據。另一方面,將AFNetworking方法放置在我的tableview單元格內,但在等待數據顯示在我的UI標籤中存在滯後時間。有任何想法嗎?iOS - 在AFNetworking之外使用responseObject

ViewController.h

@property (strong, nonatomic) NSMutableArray *neighbourData; 

ViewController.m

- (void)viewDidLoad { 
     [super viewDidLoad]; 


     NSMutableDictionary *viewParams = [NSMutableDictionary new]; 
     [viewParams setValue:@"u000" forKey:@"view_name"]; 
     [DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) { 

      self.neighbourData = [responseObject mutableCopy]; 
      NSLog(@"This is the neighbourdata %@",self.neighbourData); 


     } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
      NSLog(@"Failure: %@", [error localizedDescription]); 
     }]; 

     } 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *NetworkTableIdentifier = @"sidebarCell"; 

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 

    sidebarCell *cell = (sidebarCell *)[tableView dequeueReusableCellWithIdentifier:NetworkTableIdentifier]; 
    if (cell == nil) 

    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"sidebarCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

     NSDictionary *userName = [self.neighbourData objectAtIndex:indexPath.row]; 
     [[cell username] setText:[userName objectForKey:@"users_name"]]; 

     NSDictionary *userBio = [self.neighbourData objectAtIndex:indexPath.row]; 
     [[cell userDescription] setText:[userBio objectForKey:@"userbio"]]; 


    return cell; 

} 
+0

爲什麼避風港;噸您儘快重新加載表作爲你有你的反應.. –

+0

'self.neighbourData = [responseObject mutableCopy]'後不久,這條線,你應該重新加載你的表格。還要確保你的數據源是這個鄰居數據。也嘗試以不同的方式對nsarray進行品種匹配,比如'self.neighbourData =(NSMutableArray *)responseObject;' –

回答

0

您可以與性反應的對象初始化neighbourData或只是通過其refrence您ARRY,然後重新加載表。它會工作

self.neighbourData = [NSMutableArray alloc]initWithArry: responseObject]]; 
[yourTableView reloadData]; 

OR

self.neighbourData = (NSMutableArray *)responseObject; 
[yourTableView reloadData]; 
+0

哦,你很好:)謝謝你。 – Brittany