RubyMotionSamples 確認 (5)

手が動かないのですが、とりあえずだらだらと simulator でごにょごにょし始めてみるなど。
RubyMotionSamples の ios ディレクトリの中は以下になってます。

$ ls
Beers
CircleLayout
Fonts
GestureTable
Hello
HelloGL
Locations
Mustache
Paint
PaintHTML
StoryboardCustoms
TicTacToe
Timer
Trollify
Tweets

上から順に rake して動作を確認。

Beers

地図に pin があってそれをタップすると吹き出しが出てくる。矢印なボタンをタップすると詳細画面 (?) に遷移。iOS な戻るボタンで戻れます。また、iOS 特有のタブによる切り替えで Map と List な画面切り替えが可能になってますね。
ええと

  • タブで云々な ViewController は UITabBarCOntroller というクラス
  • UITabBarController#viewControllers なクラスの tabBarItem という属性は UITabBarItem というクラスのオブジェクトを設定してあげれば良い模様
    • タイトルとアイコン
  • Map な ViewController を見ると MKMapView というクラスを使って地図なソレを、に見えます
  • List なソレは UITableViewController を継承してます
    • これ、Android で言う ListView になるのかな

丸い矢印なボタンに関する記述が無いように見えるな、と思ったら以下な記述がある行のナニを組み立ててる記述で

  def tableView(tableView, cellForRowAtIndexPath:indexPath)
    cell = tableView.dequeueReusableCellWithIdentifier(CELLID) || begin
      cell = UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:CELLID)
      cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton
      cell
    end

    beer = Beer::All[indexPath.row]
    cell.textLabel.text = beer.title
    cell
  end

UITableViewCellAccessoryDetailDisclosureButton てのがそのボタンなのか。で、タップされた時のナニが以下らしい。

  def tableView(tableView, accessoryButtonTappedForRowWithIndexPath:indexPath)
    beer = Beer::All[indexPath.row]
    controller = UIApplication.sharedApplication.delegate.beer_details_controller
    navigationController.pushViewController(controller, animated:true)
    controller.showDetailsForBeer(beer)
  end

直接てきと言えばあまりにも直接的です。あと遷移のあたりの記述に関する理解が若干微妙。つうかドキュメント完全スルーで読んでるあたりもダウトですね。
ええと、UIApplication.sharedApplication.delegate は AppDelegate なオブジェクトを取得するための手段なのか。で、以下なメソドが定義されておりました。

  def beer_details_controller
    @beer_details_controller ||= BeerDetailsController.alloc.init
  end

成程、こうやって画面遷移するのか。つうか、navigationController て何だ。ええと、UINavigationController というクラスは階層的な画面遷移を管理云々という情報あり。そして ViewController 自身を管理しているソレは self.navigationController で取得できる模様。
ので

  • 自分を push して
  • BeerDetailsController#showDetailsForBeer を呼び出し

という形になってるのか。定義が以下。

  def showDetailsForBeer(beer)
    navigationItem.title = beer.title
    request = NSURLRequest.requestWithURL(beer.url)
    view.loadRequest(request)
  end 

これが一連の画面遷移になるのかな。でもこうして見るに iOS も stack 方式なんですね。ちなみに BeerDetailsController が云々してるのは UIWebView という View な模様。

CircleLayout

丸いオブジェクトが○を作ってます。タップしたら丸いオブジェクトが消えますね。何も無い場所をタップすると○が増えることが判明。むむ。README が以下となっております。

CircleLayout.app

This sample demonstrates the following concept: UICollectionView

This sample is a port of WWDC 2012's 219 session sample code.

早速中身を確認。AppDelegate な定義が以下。

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @window.rootViewController = ViewController.alloc.initWithCollectionViewLayout(CircleLayout.new)
    @window.makeKeyAndVisible
    true
  end
end

ViewController および CircleLayout は自分で定義、ですね。ちなみに ViewController は UICollectionViewController というクラスを継承している模様です。あ、Cell というクラスが○を表現するソレにあたるのか。
ええと、ViewController の viewDidLoad が以下な定義になってて

  def viewDidLoad
    @cell_count = 20
    tap = UITapGestureRecognizer.alloc.initWithTarget(self, action: :'handleTapGesture:')
    collectionView.addGestureRecognizer(tap)
    collectionView.registerClass(Cell, forCellWithReuseIdentifier:CellIdentifier)
    collectionView.backgroundColor = UIColor.scrollViewTexturedBackgroundColor
  end

なんとなく意味は理解できるような気がするのですが、UICollectionViewController の collectionView という属性は何なのか。つうか UICollectionView というのは iOS6 で追加、な view なんですね。

今日はここで力尽きてしまいました

むむむ。週末、別なソレの対応を、になりそうなのですがどうなるか。色々ちょっとづつ進めるしかないのは分かってるのですが微妙。