【发布时间】:2015-12-13 21:25:30
【问题描述】:
我用 AFNetworking 发出了一个 POST 请求,然后我发出了一个 GET 请求:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",access_token] forHTTPHeaderField:@"Authorization"];
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Info: %@", responseObject);dataArray = [[NSArray alloc]initWithObjects:responseObject, nil];
self.tableViewObject.dataSource = self;
self.tableViewObject.delegate = self;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
在这里我得到一个响应对象。我想这样当你点击 UITableView 中的 responseObject 时,我会进入一个新视图,其中包含 responseObject 中的所有参数。我可以记录 responseObject,但无法将其放入我的 UITableView。我的 TableView 如下所示:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
}
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
return cell;
}
在 .h 中:
@interface MyCardsVC : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSArray *dataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableViewObject;
@end
我做错了什么?
【问题讨论】:
-
您是否已将情节提要中的
UITableView连接到您的IBOutlettableViewObject? -
嗯,我不确定你的意思@JamesZaghini
-
我已经右键单击并拖动了插座,如您在 .h 文件中看到的那样,如果这是您的意思?
-
是的,我就是这个意思。你的代码对我来说看起来不错。最明显的事情是你还没有初始化
dataArray,所以它是nil。或者,您还没有按照之前的评论连接tableViewObject。尝试设置一些断点并打印出tableViewObject和dataArray的值。 -
我可以取出 dataArray 但不能取出 tableViewObject...@JamesZaghini
标签: ios objective-c uitableview afnetworking