简体   繁体   English

由于“内部”保护级别 swift 3 而无法访问

[英]inaccessible due to 'internal' protection level swift 3

I am getting this error "'removeCircleLabel' is inaccessible due to 'internal' protection level" on this line of code.我在这行代码中收到此错误“'removeCircleLabel' 由于'内部'保护级别而无法访问”。 I was adding CVCalendar Library to my project.I added the pod but i when i am adding the view controller code in my project that time its giving me this error.我正在将 CVCalendar 库添加到我的项目中。我添加了 pod,但是当我在我的项目中添加视图控制器代码时,它给了我这个错误。

@IBOutlet weak var calendarView: CVCalendarView!

  @IBAction func removeCircleAndDot(sender: AnyObject) {
    if let dayView = selectedDay {
        calendarView.contentController.removeCircleLabel(dayView)// **error on this line** 

        if dayView.date.day < randomNumberOfDotMarkersForDay.count {
            randomNumberOfDotMarkersForDay[dayView.date.day] = 0
        }

        calendarView.contentController.refreshPresentedMonth()
    }
}

 public typealias ContentViewController = CVCalendarContentViewController

 public final class CVCalendarView: UIView {
// MARK: - Public properties
public var manager: Manager!
public var appearance: Appearance!
public var touchController: TouchController!
public var coordinator: Coordinator!
public var animator: Animator!
public var contentController: ContentViewController!
public var calendarMode: CalendarMode!

public var (weekViewSize, dayViewSize): (CGSize?, CGSize?)
}


// MARK: Delete circle views (in effect refreshing the dayView circle)
extension CVCalendarContentViewController {
  func removeCircleLabel(_ dayView: CVCalendarDayView) {
    for each in dayView.subviews {
        if each is UILabel {
            continue
        } else if each is CVAuxiliaryView {
            continue
        } else {
            each.removeFromSuperview()
        }
    }
  }
}

MY View Controller Code我的视图控制器代码

 import UIKit
 import CVCalendar


class MainPageViewController: UIViewController, UITableViewDelegate,     
UITableViewDataSource {

struct Color {
    static let selectedText = UIColor.white
    static let text = UIColor.black
    static let textDisabled = UIColor.gray
    static let selectionBackground = UIColor(red: 0.2, green: 0.2, blue: 1.0, alpha: 1.0)
    static let sundayText = UIColor(red: 1.0, green: 0.2, blue: 0.2, alpha: 1.0)
    static let sundayTextDisabled = UIColor(red: 1.0, green: 0.6, blue: 0.6, alpha: 1.0)
    static let sundaySelectionBackground = sundayText
}

// MARK: - Properties
@IBOutlet weak var calendarView: CVCalendarView!
@IBOutlet weak var menuView: CVCalendarMenuView!
@IBOutlet weak var monthLabel: UILabel!
@IBOutlet weak var daysOutSwitch: UISwitch!

fileprivate var randomNumberOfDotMarkersForDay = [Int]()

var shouldShowDaysOut = true
var animationFinished = true

var selectedDay:DayView!

var currentCalendar: Calendar?

override func awakeFromNib() {
    let timeZoneBias = 480 // (UTC+08:00)
    currentCalendar = Calendar.init(identifier: .gregorian)
    if let timeZone = TimeZone.init(secondsFromGMT: -timeZoneBias * 60) {
        currentCalendar?.timeZone = timeZone
    }
}


@IBOutlet weak var topCalBtnView = UIView()
@IBOutlet weak var sideBtnView = UIView()
@IBOutlet weak var calendarBigView = UIView()
@IBOutlet weak var filterBtn = UIButton()
@IBOutlet weak var calTable = UITableView()
@IBOutlet weak var calView = UIView()
var calendarContectObj = CVCalendarContentViewController()


convenience init() {
    self.init(nibName:nil, bundle:nil)
}

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.isHidden = true

    //Calendar Stuff
    if let currentCalendar = currentCalendar {
        monthLabel.text = CVDate(date: Date(), calendar: currentCalendar).globalDescription
    }

    randomizeDotMarkers()
    // Do any additional setup after loading the view.
}

override func viewWillAppear(_ animated: Bool) {
    self.setLayout()
    navigationController?.interactivePopGestureRecognizer?.isEnabled = false

}

func setLayout(){
    ConstantFile.roundViewCorner(customVw: topCalBtnView!)
    ConstantFile.roundViewCorner(customVw: sideBtnView!)
    ConstantFile.roundViewCorner(customVw: calendarBigView!)
    ConstantFile.makeRoundBtnWithCornerRadius(btn: filterBtn!, cornerRadius: 0.02)
    ConstantFile.roundTableViewCorner(tableVw: calTable!)

}

//Mark:- IBAction
@IBAction func toggleMenuBtn(_ sender: Any) {
    let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.centerDrawwerController?.toggle(MMDrawerSide.left, animated: true, completion: nil)
}

//MARK:- UITableView Delegate and Data Source
func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 4
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellId")
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)
    return cell
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

//Mark:- Calendar Stuff
@IBAction func removeCircleAndDot(sender: AnyObject) {
    if let dayView = selectedDay {
        calendarView.contentController.removeCircleLabel(dayView)

        if dayView.date.day < randomNumberOfDotMarkersForDay.count {
            randomNumberOfDotMarkersForDay[dayView.date.day] = 0
        }

        calendarView.contentController.refreshPresentedMonth()
    }
}

@IBAction func refreshMonth(sender: AnyObject) {
    calendarView.contentController.refreshPresentedMonth()

    randomizeDotMarkers()
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    calendarView.commitCalendarViewUpdate()
    menuView.commitMenuViewUpdate()
}

private func randomizeDotMarkers() {
    randomNumberOfDotMarkersForDay = [Int]()
    for _ in 0...31 {
        randomNumberOfDotMarkersForDay.append(Int(arc4random_uniform(3) + 1))
    }
}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

By default all the methods, variable, constants, etc are internal.默认情况下,所有方法、变量、常量等都是内部的。 With internal protection level those methods, variable, constants, etc are not accessible outside a module.在内部保护级别下,这些方法、变量、常量等在模块外部是不可访问的。

removeCircleLabel(:_) is an internal method of the calendar module, you need make it public to access it. removeCircleLabel(:_)是日历模块的内部方法,您需要公开它才能访问它。

Also do read: What is the 'open' keyword in Swift?另请阅读: Swift 中的“open”关键字是什么? This explains when you should use public and open.这解释了何时应该使用 public 和 open。

In my quick search i found the function removeCircleLabel in CVCalendarContentViewController on GitHub .在我的快速搜索中,我在GitHub 上removeCircleLabel中找到了CVCalendarContentViewController函数。

// MARK: Delete circle views (in effect refreshing the dayView circle)
extension CVCalendarContentViewController {
    func removeCircleLabel(_ dayView: CVCalendarDayView) {
        for each in dayView.subviews {
            if each is UILabel {
                continue
            } else if each is CVAuxiliaryView {
                continue
            } else {
                each.removeFromSuperview()
            }
        }
    }
}

it clearly you can access this method from your controller.很明显,您可以从控制器访问此方法。 There is no protection.Please check your calendarView source with latest one.没有保护。请检查您的日历查看源最新的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由于“内部”保护级别为swift 4,因此无法访问扩展初始化程序 - Extension initializer is inaccessible due to 'internal' protection level swift 4 由于“内部”保护级别,无法访问初始化程序-Swift 4 iOS - initializer is inaccessible due to 'internal' protection level - Swift 4 iOS 由于“内部”保护级别,无法访问 phoneFieldChanged&#39; - phoneFieldChanged' is inaccessible due to 'internal' protection level 由于“私有”级别的保护,无法访问“ restoreProgress”-Swift - 'restoreProgress' is inaccessible due to 'private' level protection - swift Swift-由于具有&#39;fileprivate&#39;保护级别,无法访问&#39;textFields&#39; - Swift - 'textFields' is inaccessible due to 'fileprivate' protection level iOS-由于“内部”保护级别,无法访问“ val”(来自我的pod) - iOS - 'val' is inaccessible due to 'internal' protection level(from my pod) “‘isSuccess’由于‘内部’保护级别而无法访问”,AlamoFire 不像以前那样工作 - “'isSuccess' is inaccessible due to 'internal' protection level”, AlamoFire not working like before 如何使用diffrence模块编写测试? 由于“内部”保护级别,初始化程序无法访问 - How to write Test with diffrence module ? i got initializer is inaccessible due to 'internal' protection level 对于 Codable 结构,由于“私有”保护级别,“CodingKeys”不可访问 - 'CodingKeys' is inaccessible due to 'private' protection level, for a Codable Struct 框架中的单例错误:由于“私有”保护级别,无法访问初始化程序 - singleton in framework with error: initializer is inaccessible due to 'private' protection level
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM