我正在Swift项目中使用Swift以及Objective-C代码。 我知道在Swift项目中使用Objective-C代码我需要添加桥接头。我已经包含并有效地使用了Objective-C代码。要在Objective-C中使用Swift代码,我需要在.m文件中包含#import "ProjectName-Swift.h"
。pushViewController从Objective-C代码到Swift项目
现在发出我面对的是,我打电话LauchViewController.swift方法方法data.getLoadData()
func navigate() {
let data: Data = Data()
data.getLoadData()
self.navigationController!.pushViewController(DisplayCarViewController(), animated: true)
}
现在我想pushViewController另一个斯威夫特控制器DisplayCarViewController,它的tableView我必须填写数据。 这里是getLoadData的代码()
- (void)getLoadData
{
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.backgroundColor = [UIColor blackColor];
[spinner setCenter:CGPointMake([[UIScreen mainScreen] bounds].size.width/2,[[UIScreen mainScreen] bounds].size.height/2)];
[self.view addSubview:spinner];
[spinner startAnimating];
AFOAuth1OneLeggedClient *clnt = [[AFOAuth1OneLeggedClient alloc] initWithBaseURL:[NSURL URLWithString:path] key:cosumer_key secret:cosumer_secret];
[clnt getPath:@"products" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([responseObject isKindOfClass:[NSDictionary class]]) {
NSLog(@"responseObject: %@\n operation: %@", [responseObject valueForKey:@"products"], operation);
array = [[NSMutableArray alloc] init];
[array addObjectsFromArray: [responseObject valueForKey:@"products"]];
NSLog(@"Array: %@", array);
[spinner stopAnimating];
DisplayCarViewController *controller = [[DisplayCarViewController alloc] init];
[self.navigationController pushViewController:controller animated:true];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error data: %@\n Error operation: %@",error, operation);
[spinner stopAnimating];
}];
}
的问题是,应用程序停留在LauchViewController。数据成功获取,但不要移动/推送到DisplayCarViewController。我究竟做错了什么?
我不太确定你的问题 –
我想推到另一个控制器在这里DisplayCarViewController * controller = [[DisplayCarViewController alloc] init]; [self.navigationController pushViewController:controller animated:true];我无法这样做。 –
你是什么意思?什么是错误/结果? –