I am developing an ios application using swift. I am using xcode7.0.1. with TableViewController. I want to expand when I click a line and it crashes when I click it again. I am following a tutorial from gitHub . Now i ran into an errorTerminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer
for the key path "frame" from <X.expandTips 0x145d8d20> because it is not registered as an observer.'
I hope the next line of code will cause a problem.
Code of my UITableViewCell:
func checkHeight(){
expandaple_view.hidden = (frame.size.height < expandTips.expandedHeight)
}
func WatchFrameChanges() {
addObserver(self , forKeyPath: "frame", options: .New, context: nil )
checkHeight()
}
func ignoreFrameChanges(){
removeObserver(self, forKeyPath: "frame")
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if keyPath == "frame"{
checkHeight()
}
}
And in my TableViewController code:
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
(cell as! expandTips) . WatchFrameChanges()
}
override func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
(cell as! expandTips) . ignoreFrameChanges()
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if (indexPath == selectedIndexPath ){
return expandTips.expandedHeight
}else {
return expandTips.defaultHeight
}
}
I am new to ios. Hope this should be a simple problem. Please help me solve this problem.
I do not know what details need to be published here. Please comment if I want to add more details.