Ich möchte UITableView über UIView hinzufügen, die eine Unterklasse von GooeySlideMenu ist. Wie im Beispiel in git gezeigt habe ich UITableView statt UIButtons erstellt, aber Delegate Methoden werden nicht aufgerufen.UITableView Delegate-Methoden werden nicht aufgerufen, wenn auf GooeySlideMenu hinzugefügt
Unten ist mein Code als Referenz:
class GooeySlideMenu: UIView {
fileprivate var _option: MenuOptions
fileprivate var keyWindow: UIWindow?
fileprivate var blurView: UIVisualEffectView!
fileprivate var helperSideView: UIView!
fileprivate var helperCenterView: UIView!
fileprivate var diff: CGFloat = 0.0
fileprivate var triggered: Bool = false
fileprivate var displayLink: CADisplayLink?
fileprivate var animationCount: Int = 0
fileprivate var myTableView: tableViewCustomClass = tableViewCustomClass()
init(options: MenuOptions) {
_option = options
if let kWindow = UIApplication.shared.keyWindow{
keyWindow = kWindow
let frame = CGRect(
x: -kWindow.frame.size.width/2 - options.menuBlankWidth,
y: 0,
width: kWindow.frame.size.width/2 + options.menuBlankWidth,
height: kWindow.frame.size.height)
super.init(frame:frame)
} else {
super.init(frame:CGRect.zero)
}
setUpViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func draw(_ rect: CGRect) {
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: frame.width-_option.menuBlankWidth, y: 0))
path.addQuadCurve(to: CGPoint(x: frame.width-_option.menuBlankWidth, y: frame.height), controlPoint: CGPoint(x: frame.width-_option.menuBlankWidth+diff, y: frame.height/2))
path.addLine(to: CGPoint(x: 0, y: frame.height))
path.close()
let context = UIGraphicsGetCurrentContext()
context?.addPath(path.cgPath)
_option.menuColor.set()
context?.fillPath()
}
func trigger() {
if !triggered {
if let keyWindow = keyWindow {
keyWindow.insertSubview(blurView, belowSubview: self)
UIView.animate(withDuration: 0.3, animations: { [weak self]() -> Void in
self?.frame = CGRect(
x: 0,
y: 0,
width: keyWindow.frame.size.width/2 + (self?._option.menuBlankWidth)!,
height: keyWindow.frame.size.height)
})
beforeAnimation()
UIView.animate(withDuration: 0.7, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.9, options: [.beginFromCurrentState,.allowUserInteraction], animations: { [weak self]() -> Void in
self?.helperSideView.center = CGPoint(x: keyWindow.center.x, y: (self?.helperSideView.frame.size.height)!/2);
}, completion: { [weak self] (finish) -> Void in
self?.finishAnimation()
})
UIView.animate(withDuration: 0.3, animations: { [weak self]() -> Void in
self?.blurView.alpha = 1.0
})
beforeAnimation()
UIView.animate(withDuration: 0.7, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: [.beginFromCurrentState,.allowUserInteraction], animations: { [weak self]() -> Void in
self?.helperCenterView.center = keyWindow.center
}, completion: { [weak self] (finished) -> Void in
if finished {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(GooeySlideMenu.tapToUntrigger))
self?.blurView.addGestureRecognizer(tapGesture)
self?.finishAnimation()
}
})
// animateButtons()
myTableView.reloadData()
triggered = true
}
} else {
tapToUntrigger()
}
}
}
extension GooeySlideMenu {
fileprivate func setUpViews() {
if let keyWindow = keyWindow {
blurView = UIVisualEffectView(effect: UIBlurEffect(style: _option.blurStyle))
blurView.frame = keyWindow.frame
blurView.alpha = 0.0
helperSideView = UIView(frame: CGRect(x: -40, y: 0, width: 40, height: 40))
helperSideView.backgroundColor = UIColor.red
helperSideView.isHidden = true
keyWindow.addSubview(helperSideView)
helperCenterView = UIView(frame: CGRect(x: -40, y: keyWindow.frame.height/2 - 20, width: 40, height: 40))
helperCenterView.backgroundColor = UIColor.yellow
helperCenterView.isHidden = true
keyWindow.addSubview(helperCenterView)
backgroundColor = UIColor.clear
keyWindow.insertSubview(self, belowSubview: helperSideView)
addUItableView()
// addButton()
}
}
fileprivate func addUItableView(){
myTableView.frame = CGRect(x: 0, y: 20, width: 300, height: 200)
myTableView.backgroundColor = UIColor.white
myTableView.delegate = tableViewCustomClass() as? UITableViewDelegate
myTableView.dataSource = tableViewCustomClass() as? UITableViewDataSource
addSubview(myTableView)
}
was ist die Verwendung von myTableView.delegate = tableViewCustomClass() wie? UITableViewDelegate – KKRocks
Delegat Methoden, die ich wie zuvor geschrieben aufrufen. Irgendwas falsch? – user2931321
Wo deklarierte Delegate-Methoden für die Tabellenansicht? – KKRocks