MacにPythonとSphinx, blockdiagをセットアップ
HomebrewでPython(とPIL)をインストール(Macデフォルトと環境を分ける)
brew install python pil
.zshrc (.bashrc) に下記を追加
export PATH=/usr/local/share/python:$PATH
Pythonのインストールを確認
which python && python -V > /usr/local/bin/python > Python 2.7.3
Sphinx と blockdiag をインストール
pip install Sphinx blockdiag sphinxcontrib-blockdiag
Sphinxでプロジェクトを作成
mkdir ~/sphinx-test && cd ~/sphinx-test sphinx-quickstart
ウィザードが完了したら、
make html && open build/index.html
UITableViewCellのカスタムセルでUILabelの複数行表示をうまいことする
メモエントリ。
複数行表示したいUILabelを置いたカスタムセルを作って、UILabelの高さ調整とセルの高さ調整をうまいことまとめる方法。
// MyTableViewController.m - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *text = @"cell text"; // indexPathから該当セル用のデータをよしなに。 CGFloat cellHeight = 83; // カスタムセルのデフォルトのheight CGFloat textHeight = 22; // カスタムセル内の複数行表示したいラベルのデフォルトのheight UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:18]; // IBで設定したのと同じに。 CGSize size = CGSizeMake(292, 4000); // カスタムセル内のラベルのwidth。heightは適当に。 CGSize textSize = [text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeCharacterWrap]; // IBで設定したのと同じlineBreakModeにする。 cellHeight += (textSize.height - textHeight); return cellHeight; }
// MyCustomCell.m - (void)layoutSubviews { [super layoutSubviews]; 〜〜レイアウトコード // ラベルはnumberOfLines = 0, lineBreakModeにはCharacterWrapかWordWrap CGRect frame = [label frame]; frame.size = CGSizeMake(292, 0); // ラベルのwidthを都度指定。セルは再利用されるので、テキストが短い状態でフィットされるとその後が困ったことになるため。 [label setFrame:frame]; [label sizeToFit]; 〜〜レイアウトコード }
あとはIBでAutosizingを調整。
対象のラベルより下にUIパーツがある場合は、それらのボトムマージンを固定にし、ラベルのボトムマージンは固定しない。
カスタムセルはこのあたりを。
http://d.hatena.ne.jp/KishikawaKatsumi/20081024/1224857278
UINavigationController配下のviewControllerのviewWillAppear/viewDidAppearが呼ばれない件
ハマったので、メモ。
UINavigationControllerのrootViewControllerにUITableViewControllerを設定した状況で、UITableViewController側のviewWillAppear/viewDidAppearが実行されなかった。
ググったところ、以下を参考に何とか解決。
http://discussions.apple.com/thread.jspa?threadID=1549270
UINavigationControllerを管理するController(もしくはAppDelegate)にて、
UINavigationControllerDelegateプロトコルを実装
navigationController.delegate = self (もしくはIBでoutlet接続)
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [viewController viewWillAppear:animated]; } - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [viewController viewDidAppear:animated]; }
ちなみに呼ばれる順番は、
- willShowViewController
- viewWillAppear
- didShowViewController
- viewDidAppear
となります。
以上。