2017-11-03 5 views
0

私はAPIからのアドレスを持って、正しく表示されなかった場合は、下記スウィフト3のテーブルビューセルでスーパービューからラベルを取り除くときにラベルを再び取り戻すには?

enter image description here

が、ここに示したようにただ一つのラベルを示す利用可能なアドレスが存在しないときに、画面からラベルを削除するには、コードremove from superViewを使用していましたそして

enter image description here

以下のようにそれ自体がそれに入射したコードが画像に表示されているが、適切な画像は、名前ラベル、アドレスラベルと携帯電話番号で表示されるべきですラベル誰も私のアドレスラベルと携帯電話のラベルを表示する方法を助けることができます表示から削除した後のアドレスは、APIからですか?それはラベルとラベルを隠すなど、セルの高さを動的にするには0を一定の高さを変更するために、ここで

は、高さの制約を設定して自分のコード

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     if (indexPath.section == 0) { 
      let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AddressTableViewCell 
      let dict = guestShippingAddressModel 
      self.tableDetails.isHidden = false 
      self.activityIndicator.stopAnimating() 
      self.activityIndicator.hidesWhenStopped = true 
      cell.deleteButton.tag = indexPath.row 
      if self.street?.isEmpty == true || self.street?.isEmpty == nil { 
       cell.addressLabel.isHidden = true 
       cell.mobileNumberLabel.isHidden = true 
       cell.radioButton.isHidden = true 
       cell.editButton.isHidden = true 
       cell.deleteButton.isHidden = true 
       cell.addresslabel.removeFromSuperview() 
       cell.mobileNumberlabel.removeFromSuperview() 
       cell.nameLabel.text = "No address available" 
       if delayCheck == true { 
        let when = DispatchTime.now() + 5 // change 2 to desired number of seconds 
        DispatchQueue.main.asyncAfter(deadline: when) { 
         let storyboard = UIStoryboard(name: "Main", bundle: nil) 
         let addtoCartVC = storyboard.instantiateViewController(withIdentifier: "newAddress") as! NewAddressViewController 
         self.navigationController?.pushViewController(addtoCartVC, animated: true) 
        } 
       } 
      } 
      else { 
       cell.addressLabel.isHidden = false 
       cell.radioButton.isHidden = false 
       cell.editButton.isHidden = false 
       cell.deleteButton.isHidden = false 
       cell.nameLabel.isHidden = false 
       cell.nameLabel.text = "\((dict?.firstName)!) \((dict?.lastName)!)" 
       cell.addressLabel.text = "\((self.street)!) \((dict?.city)!) \((dict?.region)!) \((dict?.postCode)!)" 
       cell.mobileNumberLabel.text = "\((dict?.telephone)!)" 
      } 
      cell.radioButton.tag = indexPath.row 
      cell.editButton.tag = indexPath.row 
      cell.deleteButton.tag = indexPath.row 
      cell.editButton.isHidden = true 
      cell.deleteButton.isHidden = true 
      cell.radioButton.addTarget(self, action: #selector(selectRadioButton(_:)), for: .touchUpInside) 
      cell.deleteButton.addTarget(self, action: #selector(deleteAction(button:)), for: .touchUpInside) 
      cell.editButton.addTarget(self, action: #selector(editButtonAction(_:)), for: .touchUpInside) 
      let checkIndex = self.checkIsRadioSelect.index(of: indexPath.row) 
      if(checkIndex != nil) { 
       cell.radioButton.isSelected = true 
       cell.editButton.isHidden = false 
       cell.deleteButton.isHidden = false 
      } 
      else 
      { 
       cell.radioButton.isSelected = false 
       cell.editButton.isHidden = true 
       cell.deleteButton.isHidden = true 
      } 
      if (checkIsPaymentRadioSelect == true) { 
       let defaultvalue = street 
       if defaultvalue?.isEmpty == false { 
        cell.radioButton.isSelected = true 
        cell.editButton.isHidden = false 
        cell.deleteButton.isHidden = false 
        addressSelected = true 
       } 
      } 
      return cell 
     } 
+0

AddressTableViewCellデザインのUIを表示してください。 –

+0

ここに私のUIデザインですhttps://i.stack.imgur.com/yX4Oh.png @NishantBhindi – user0246

+0

ここに私の元のイメージはアドレスデータhttps://i.stackと見えます。imgur.com/SOoLK.png – user0246

答えて

0

代わりの削除住所ラベルやスーパーから携帯ラベルです以下。

tblList.rowHeight = UITableViewAutomaticDimension; 
tblList.estimatedRowHeight = CGFloat(100) 
+0

ここでデータを取得すると、0から3または4にも増加する可能性があります。 – user0246

+0

私は、アドレスラベル – user0246

+0

について、Linesの数を0に設定し、テキストに基づいて高さを計算する必要があるということについて話していました。 –

0

男性は、データソースメソッドUITableViewDataSourceに多くのコードを書き込まないでください。実際に何が起こっているのかを理解し、理解することは非常に難しいです!私が本当に理解していない多くの奇妙な論理があるsoooがあります。だから私はUITableViewCellサブクラス(あなたのケースでAddressTableViewCell & NewAddressViewController

  • モデルですべての設定をするためにあなたに

    1. をお勧めします構造体/クラスのように書くことが良いですが、辞書にない
    2. activityIndicatorがで扱われるべきではありませんcellForRow方法。要求に応じて、処理/終了/失敗などが変わるかどうかが変わるはずです。
    3. cell.radioButton.tag = indexPathのようなことをしているのであれば、tableView .indexPath(forCell: UICollectionViewCell)のメソッドを持っているので間違ったことをしています。それはあなたが、細胞からいくつかのタッチを扱う場合は、indexPath
    4. 強要言うことができます - あなたは私の講義の終了あなたのViewControllerにタッチが

      func selectRadioButton(inCell cell: UICollectionViewCell) { 
          guard let indexPath = tableView.indexPath(forCell: cell) else { return } 
          // do what you need to do & you have your indexPath! = know where touch occurred 
      } 
      

    のように発生したセルを送信するセルのデリゲートを作成する必要があります - あなたのソースはあなたのセルを完全に定義する必要があります。それは、あなたが何かを表示するかどうかを示すモデルにいくつかの旗があるかどうかを示します:

    yourView.isHidden = !yourModel.isDisplayed 
    

    なぜですか?セルは再利用され、すべてのサブクラスプロパティはすべてのUI設定(可視性などが残ります)である状態を保持するためです。 googleでそれについて読んでくださいそれは私がより良いそれをしたこのテーマに関する記事がたくさんあります

    私はあなたを助けました!

  • 関連する問題