quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

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
  • CreatePostView
    • def createPostButtonPressed
      • if self.delegate.respond_to?('createPostView:didCreatePostWithDetails')
      • self.delegate.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