MotionInMotion Episode 3 - More Delegates, KVO, and Target Action
More Delegates, KVO, and Target Action - MotionInMotion
postを追加、バッジの更新などの実装
- CreatePostController
- def viewDidLoad
- @createPostView = CreatePostView.alloc.initWithFrame(self.view.frame)
- @createPostView.delegate = self
- def viewDidLoad
- CreatePostView
- KVO (key value observing)
- PostsController
- @postsModel = UIApplication.sharedApplication.delegate.postsModel
- @postsModel.addObserver(self, forKeyPath
- options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
- def observeValueForKeyPath(keyPath, ofObject:object, change:change, context:context)
- if keyPath == 'newRecordCount' && (change[NSKeyValueChangeNewKey] - change[NSKeyValueChangeOldKey]) > 0
- self.tableView.reloadData
- self.tabBarController.tabBar.items[0].badgeValue = change[NSKeyValueChangeNewKey].to_s
- def viewDidAppear(animated)
- self.tabBarController.tabBar.items[0].badgeValue = nil
- PostsController