I am developing ios app by using swift. I am using xcode7.0.1. with TableViewController. I want to expand when i click row and collapse when i click it again. I am following the tutorial from gitHub. Now i am facing the error Terminating 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 following line of code will causing the issue.
My UITableViewCell class code:
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. I hope it must be simple issue. Please someone help me to solve this.
I don't know what are the details needs to post here. Please comment if i want to add more details.