提问人:Dylon Jaynes 提问时间:9/24/2022 最后编辑:Dylon Jaynes 更新时间:9/24/2022 访问量:36
如何实例化 Storyboard ViewController?[复制]
How do I instantiate Storyboard ViewController? [duplicate]
问:
我有 objc 代码 (SUOTAViewController),我将其包含在我的 Swift 项目中。我还有一个与该 ViewController 关联的情节提要,其 storyboardID 为“suotaViewController”。
当我尝试像这样实例化它时:
func navigateToUpdateViewController(imageURL: URL) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "suotaViewController") as! SUOTAViewController
vc.imageURL = imageURL
self.navigationController?.pushViewController(vc, animated: true)
}
我收到错误“无法将类型为'UIViewController'的值转换为'SUOTAViewController'
为什么会这样?
这是我的 SUOTAViewController,如果它有帮助:
#define UIALERTVIEW_TAG_REBOOT 1
#import "SUOTAViewController.h"
@interface SUOTAViewController ()
@end
@implementation SUOTAViewController
@synthesize blockSize;
- (void)viewDidLoad {
[super viewDidLoad];
self.textView.text = @"";
storage = [ParameterStorage getInstance];
manager = storage.manager;
storage.file_url = self.imageURL;
[self.progressView setProgress:0];
[self.progressTextLabel setText:[NSString stringWithFormat:@"%d%%", 0]];
// Enable notifications on the status characteristic
[manager setNotifications:GenericServiceManager.SPOTA_SERVICE_CBUUID characteristicUUID:GenericServiceManager.SPOTA_SERV_STATUS_CBUUID enable:YES];
} ...
我已经在情节提要中将 ViewController 的类设置为“SUOTAViewController”,它与我的 Obj-C ViewController 的类相匹配。我仍然收到错误。
答: 暂无答案
评论
UIViewController