【发布时间】:2015-12-15 14:54:15
【问题描述】:
我试图在TableView 中显示responseObject,但没有显示。我可以打印出所有responseObject 的值,但在运行应用程序时TableView 中没有显示任何内容。在 .m 文件中,我在 ViewDidLoad 中有这个:
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 reloadData];
self.tableViewObject.dataSource = self;
self.tableViewObject.delegate = self;
NSLog(@"TableView: %@", _tableViewObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
如果我取消注释 [self.tableViewObject reloadData]; 它会给我这个错误:
libc++abi.dylib:以未捕获的类型异常终止 NSException
我在 .m 文件中的 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 文件如下所示:
#import <UIKit/UIKit.h>
@interface MyCardsVC : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSArray *dataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableViewObject;
@end
我不知道我做错了什么。我应该正确连接它...
【问题讨论】:
标签: ios objective-c uitableview afnetworking-2