简体   繁体   中英

Error in conforming to a protocol defined in Objective from swift code

I have the following header for ReaderViewController.h

#import <UIKit/UIKit.h>

#import "ReaderDocument.h"

@class ReaderViewController;

@protocol ReaderViewControllerDelegate <NSObject>

@optional // Delegate protocols

- (void)dismissReaderViewController:(ReaderViewController *)viewController;

@end

@interface ReaderViewController : UIViewController

@property (nonatomic, weak, readwrite) id <ReaderViewControllerDelegate> delegate;

- (instancetype)initWithReaderDocument:(ReaderDocument *)object;

@end

In a swift file

  class DetailTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {


override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    // Get the row data for the selected row
    var phrase: String = "" ;

    var document:ReaderDocument? = ReaderDocument(filePath: "/Users/Krishna/Development/XXXX/Reader.pdf", password: phrase);
    if(document != nil){
        var readerViewController:ReaderViewController  = ReaderViewController(readerDocument: document)
        readerViewController.delegate = self ;
        readerViewController.modalTransitionStyle = .CrossDissolve;
        readerViewController.modalPresentationStyle = .FullScreen;
        self.presentViewController(readerViewController, animated: true, completion: nil)
    }

func dismissReaderViewController(viewController: ReaderViewController) {

    self.dismissViewControllerAnimated(true, completion: nil)

}


}

For the line readerViewController.delegate = self ; Xcode throws a compile time exception that

Type 'DetailTableViewController' does not conform to protocol 'ReaderViewControllerDelegate' . I tried looking for solutions for other similar posts and couldn't figure out the issue. Any help is appreciated as I am new developer in iOS platform!

只需将ReaderViewControllerDelegate添加到ReaderViewControllerDelegate的第一行, DetailTableViewController告诉编译器该类符合特定的委托协议。

class DetailTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource, ReaderViewControllerDelegate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM