我有一个MainViewController和一个UITableViewController
。我通过使用自定义细分来调用UITableViewController
来添加MainViewConroller的子视图。当我独立测试UITableViewController
时,一切正常,数据在UITableView
成功填充。当我从MainViewController调用时,数据未填充在UITableView
中。我的做法有什么问题?这是通过以下代码完成的。
CustomTabBarSegue.m 的
#import "CustomTabBarSegue.h"
#import "MainViewController.h"
@implementation CustomTabBarSegue
-(void)perform{
MainViewController *rootVC = (MainViewController *)self.sourceViewController;
UIViewController *dst = (UIViewController *)self.destinationViewController;
for(UIView *view in rootVC.placeholder.subviews){
[view removeFromSuperview];
}
rootVC.currentViewController = dst;
[rootVC.placeholder addSubview:dst.view];
}
ListingViewConroller.m 的
#import "ListingViewController.h"
#import "AFNetworking.h"
#import "Constants.h"
@interface ListingViewController ()
@end
@implementation ListingViewController
@synthesize jobs;
@synthesize jobDictionary;
- (void)viewDidLoad
{
[super viewDidLoad];
[self makeOperationRequest];
}
-(void)makeOperationRequest
{
NSURL *url = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"http://localhost/api/jobs"]];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject) {
jobDictionary = (NSDictionary *)responseObject;
jobs = [jobDictionary objectForKey:@"jobs"];
[self.tableView reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error:%@,%@",error,error.userInfo);
}];
[operation start];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return jobs.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.text = [[jobs objectAtIndex:indexPath.row] objectForKey:@"CustomerName"];
cell.detailTextLabel.text = [[jobs objectAtIndex:indexPath.row] objectForKey:@"Address"];
return cell;
}
答案 0 :(得分:0)
尝试在将表视图添加为子视图后重新加载表视图。
[tableView reloadData];
可以解决你的问题。