gpt4 book ai didi

objective-c - 必须调用父类(super class) 'UITableViewController' 的指定初始值设定项

转载 作者:行者123 更新时间:2023-11-30 11:43:57 24 4
gpt4 key购买 nike

这是 Objective-C 中的头代码:

@interface DocumentCatalogViewController : UITableViewController <UITableViewDelegate,UIAlertViewDelegate,UISearchBarDelegate,UIViewControllerPreviewingDelegate,UITableViewDataSource,UIDocumentInteractionControllerDelegate>

@property NSArray *filePathsArray;
@property NSArray *filePathsArrayCopy;

-(void) openTheFileInNativeViewer : (NSURL *) destinationURL;

-(void) openTheFileInOtherApps : (NSURL *) destinationURL;

@property UISearchBar *searchBar;

@property (strong, nonatomic) IBOutlet UIProgressView *progressView;

-(void)refreshDataAfterDownloading;

-(UIImage *) fileIconForTheCell : (NSString *) documentType;

-(UISearchBar *) setSearchBar;

-(void) openFile : (NSURL *) destinationURL doctype : (NSString *) documenttype;

+(id) sharedManager;

@end

这是 Objective-C 中的 .m 代码:​​

@interface DocumentCatalogViewController()

@property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;
@property (strong) NSArray *files;
@property (strong) NSArray *SearchedFiles;

@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UIButton *cancelButton;
@property (nonatomic, strong) id previewingContext;
@property (nonatomic ,strong) UIDocumentInteractionController *documentInteractionController;
@property (nonatomic) BOOL hasCompatibleApps;
@property (nonatomic, strong) DocumentDownloadHandler *SessionWrapper;

@end

@implementation DocumentCatalogViewController
@dynamic refreshControl;
@synthesize searchBar;

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
// Custom initialization
self.title = NSLocalizedString(@"mdm.agent.common.documents", nil);
self.progressView =[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 5.0f);
self.progressView.transform = transform;

[self.progressView setFrame:CGRectMake(0,60, self.tableView.bounds.size.width, 10)];
self.progressView.progressTintColor=[UIColor greenColor];

}
return self;
}

+ (id) sharedManager {

static dispatch_once_t onceToken;
static DocumentCatalogViewController *sharedCatalogManager;
dispatch_once(&onceToken, ^{
sharedCatalogManager = [[[self class] alloc] init];
});
return sharedCatalogManager;
}

- (instancetype)init {
self = [super init];

return self;
}

将其转换为 Swift 时,我无法转换单例函数,因为 dispatch_once 已弃用。所以我创建了一个静态变量,如下所示。

Swift 中的代码片段

class DocumentCatalogViewController: UITableViewController, UIViewControllerPreviewingDelegate, UISearchBarDelegate, UIDocumentInteractionControllerDelegate, UIAlertViewDelegate {
var filePathsArray = [Any]()
var filePathsArrayCopy = [Any]()
var searchBar: UISearchBar?
@IBOutlet var progressView: UIProgressView!

var managedObjectContext: NSManagedObjectContext?
var files = [File]()
var searchedFiles = [File]()
var button: UIButton?
var cancelButton: UIButton?
var previewingContext: Any?
var documentInteractionController: UIDocumentInteractionController
var hasCompatibleApps = false
var sessionWrapper: DocumentDownloadHandler?
//here
static let shared = DocumentCatalogViewController()
//but this shows a error **Cannot invoke initializer for type 'DocumentCatalogViewController' with no arguments**

override init(style: UITableViewStyle) {
super.init(style: .grouped)
title = NSLocalizedString("mdm.agent.common.documents", comment: "")
progressView = UIProgressView(progressViewStyle: .bar)
let transform = CGAffineTransform(scaleX: 1.0, y: 5.0)
progressView.transform = transform
progressView.frame = CGRect(x: 0, y: 60, width: tableView.bounds.size.width, height: 10)
progressView.progressTintColor = UIColor.green

}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//fatalError("init(coder:) has not been implemented")
}

所以,我创建了一个空的初始化函数,init()

init(){
super.init()
}

但随后它显示错误:

Must call a designated initializer of the superclass 'UITableViewController'

最佳答案

您正在调用 UITableViewController 父类(super class)不支持的 super.init(),请将其更改为 initWithStyle

关于objective-c - 必须调用父类(super class) 'UITableViewController' 的指定初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49050723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com