Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-在AFNetworking之外使用responseObject_Ios_Objective C_Uitableview_Afnetworking - Fatal编程技术网

iOS-在AFNetworking之外使用responseObject

iOS-在AFNetworking之外使用responseObject,ios,objective-c,uitableview,afnetworking,Ios,Objective C,Uitableview,Afnetworking,我想在我的tableview单元格中显示从下面的AFNetworking调用接收的responseObject。我在头文件(neighbourData)中创建了一个NSMutableArray属性,认为将responseObject分配给它可能有效。尽管如预测的那样,我似乎无法使用AFNetworking方法之外的数据。另一方面,将AFNetworking方法放在我的tableview单元格中是可行的,但是在等待数据显示在我的UIlabels中时会有一段延迟时间。有什么想法吗 ViewContr

我想在我的tableview单元格中显示从下面的AFNetworking调用接收的responseObject。我在头文件(neighbourData)中创建了一个NSMutableArray属性,认为将responseObject分配给它可能有效。尽管如预测的那样,我似乎无法使用AFNetworking方法之外的数据。另一方面,将AFNetworking方法放在我的tableview单元格中是可行的,但是在等待数据显示在我的UIlabels中时会有一段延迟时间。有什么想法吗

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;

}

您可以使用response对象初始化neighbourData,或者将其引用传递给arry,然后重新加载表。它会起作用的

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


为什么是避风港;t收到响应后立即重新加载表..
self.neighbourData=[responseObject mutableCopy]在这一行之后不久,您应该重新加载表。还要确保表的数据源是此相邻数据。还可以尝试以不同的方式对nsarray进行分类,例如
self.neighbourData=(NSMutableArray*)responseObject
self.neighbourData = (NSMutableArray *)responseObject;
[yourTableView reloadData];