現在のモーダル ビュー コントローラーはいつでも閉じることができます。これを行う「正しい方法」はありません。ユーザーがテーブル ビュー セルを選択すると、UITableViewDelegate メソッドでモーダル ビュー コントローラーを閉じることができます。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
/* dismiss your modal view controller
through the UIViewController method
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
or through the UINavigationViewController method
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
depending on the way you presented it in the first place. */
}
また、長いテキストを含むオプションを表示するには、テーブル ビューが最適です。UITableViewDelegate メソッドを使用して、テーブル ビューの各セルの高さを調整できます。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return /*appropriate cell height in order to accommodate long text */;
}
また、任意のテキストの高さを計算したい場合は、次のように実行できます。
// get the table view width
CGFloat tableViewWidth = [tableView bounds].size.width;
// get your piece of text
NSString *text = /*your text*/
CGFloat textHeight = [text sizeWithFont:[UIFont systemFontOfSize:18]/*or any font you want*/
forWidth:tableViewWidth
lineBreakMode:NSLineBreakByWordWrapping].height;