2017-05-28 9 views
0

私は最後のスタティックセルボトムセパレータラインを取り除くために以下のコードを使用しています。テーブルをセーブすると、テーブルセパレータが表示されます。最後のスタティックセルセパレータラインは、テーブルビューをリロードした後に表示されます

スーパーVCでのみコード:

override func viewDidLoad() { 
    super.viewDidLoad() 
    let footerFrame = CGRect(x: 0.0, y: 0.0, width: 
    tableView.frame.size.width, height: 1.0) 
    tableView.tableFooterView = UIView(frame: footerFrame) 
} 

そして呼び出した後:私の子供ののtableView(didSelectRowAt indexPath:_)で

fileprivate func showDatePicker() 
{ 
    datePicker.setValue(UIColor.white, forKey: "textColor") 
    showsDatePicker = true 

    tableView.beginUpdates() 
    tableView.endUpdates() 

    tableView.contentInset = UIEdgeInsets(top: -20.0, left: 0.0, 
    bottom: 0.0, right: 0.0) 
} 

私はちょうどの日付ピッカーでセルの高さを変更しています:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 

    guard showsDatePicker else { 
     switch indexPath.row { 
     case CellIndex.withDatePicker: 
      return 0.0 
     default: 
      return 44.0 
     } 
    } 

    switch indexPath.row { 
     case CellIndex.withDatePicker: 
      return 217.0 
     default: 
      return 44.0 
     } 
} 

以降、私は区切り線を描いています!たぶんそれはSTATICセルの使用のため、唯一の方法は、各viewControllerに空のビューをストーリーボードに追加することです? tableView.tableFooterView = UIView()viewDid/WillLayoutSubviewsに置き換えると、画面効果がなくなります。私は、ストーリーボードのすべてのコントローラに空白のビューを追加したくないのですが、プログラムでそれを行う方法がありますか?

+1

コードを共有していただけますか? –

+0

Yeapは、必ず、しかしあまりない静的な細胞とのtableViewのための私のスーパークラスでのviewDidLoad(){ super.viewDidLoad() tableView.tableFooterView =のUIView() } FUNC –

+0

オーバーライドを共有する、と私はリロードするまでには、セパレータを削除しますtableView –

答えて

0

最後のセルを表示する前に。

if indexPath.row == Your_last_Cell { 

    cell.separatorInset = UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0); 

} 

最小の高さとフッターを作成します。

func tableView(_ tableView: UITableView, 
heightForFooterInSection section: Int) -> CGFloat{ 

// This will create a "invisible" footer 
    return 0.01f; //CGFLOAT_MIN 
} 

OR

func tableView(_ tableView: UITableView, 
viewForFooterInSection section: Int) -> UIView?{ 

UIView(frame: CGRectZero) 

} 
+0

ありがとうございます。もしあれば、もっと汎用的な方法を探しています。 –

+0

もっと一般的な方法を探しているなら、単に 'tableview'デフォルトのセパレータ 'tableView.separatorStyle = UITableViewCellSeparatorStyle.none'と独自のカスタムセパレータを作成します。 – Maddy

+0

出力は同じですが、再ロードするまでセパレータを隠します –

0

次のようにこの結果を達成するために私のアプローチがあり、あなたのviewDidLoad機能で

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Add this line 
    yourTableView.tableFooterView = UIView() 
} 

がお手伝いします

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
var cell: UITableViewCell? 
switch indexPath.section { 
    case 0: 
     cell = tableView.dequeueReusableCellWithIdentifier("yourfirstcell") 
     if indexPath.row == yourLastRowIndex { 
     self.separatorInset = UIEdgeInsetsMake(0, self.bounds.size.width, 0, 0) 
    } 
    case 1: 
     cell = tableView.dequeueReusableCellWithIdentifier("yoursecondcell") 
    default: 
     break 
    } 
    return cell! 
} 

、テーブルビュー

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 2 
} 

そして、あなたのcellForRowAtIndexPath関数のためにこのアプローチをセクションの数を定義します。

+0

ありがとう、しかし私は静的なセルを使用していますし、 'cellForRowAtIndexPath'を実装したくありません。私は他の細胞のために戻るでしょうか?ちょうど 'UITableViewCell()'はできません。 –

+0

@DmitriyIvashinはシナリオごとに答えを更新しました。 –

関連する問題