我正在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];我無法這樣做。 –
你是什麼意思?什麼是錯誤/結果? –