2017年10月11日 星期三

iOS簡繁互轉

UIAlertController客製化

根據🍎的文件
The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

如果不想理他的話,就用以下的方法吧!

  1. 打開contentViewController的束縛
    @interface UIAlertController (ContentViewController)
    @property (nonatomic,retain) UIViewController * contentViewController;
    @end
  2. 呼喚神秘的contentViewController
    alertController.contentViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "contentViewController")
  3. 如果,使用tableview的話,記得加上
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
            
        // make UITableView fit to content's size
        self.preferredContentSize = self.tableView.contentSize

    }

code