Posts

Set one section height is constant and other sections height will be dynamic iOS swift

 Problem: I want to set one section height was static and other section heights will be dynamic.How can i achieve that? Solution: func tableView ( _ tableView: UITableView , heightForRowAt indexPath: IndexPath ) -> CGFloat {         switch indexPath. section {         case 0 :             return 55         default :             return UITableView . automaticDimension         }     }

How to set datasource for UICollectionviewcell and title iOS swift?

Problem:  I want to set the datasource to the collectionview with rxswift to set the title also Solution:      private   lazy   var   dataSource   = RxTableViewSectionedReloadData Source< SectionOfColl > (configureCell:   configureCell , titleForHeaderInSection: {           ds, index   in           return   ds.sectionModels[index]. model . title       }) The above datasource will return the title for the collectionview section.

While show toast in oneVIewcontroller after dismiss it's gone iOS swift

 Problem: I'm having one viewcontroller that had one action.After the action it will show one toast. After display toast i want to dismiss the viewcontroller.But now i shown the toast, but inside the viewcontroller that toast shown.After dismiss in fraction of second it's gone. So user may not be able to view the toast.How to solve that? Solution: The above problem will be solved after some fraction of seconds you can show the toast with the current viewcontroller in visible.                      DispatchQueue. main . asyncAfter ( deadline : . now () + 0.6 ) {                          if let topController = UIApplication . topViewController () {                      showToast ( message : message ?? "" , seconds : 0.5 )    }                   }...

Password textfield have shown option with automatic paste option Not able to type on textfield iOS swift

 Problem: Password textfield have shown option with automatic paste option with yellow color.After that not able to type on textfield .How to solve that? Solution: You can easily solve that by using the below code. extension UITextField {      func removePasswordOverlay () {         if #available ( iOS 10.0 , *) {             if #available ( iOS 12 , *) {                 textContentType = . oneTimeCode             } else {                 textContentType = UITextContentType ( rawValue : "" )             }         }     } } You can call the above extension as like below.         p asswordTF . removePasswordOverlay ()

Remove the viewcontroller in Navigationcontroller iOS swift

 Solution: I want to remove one viewcontroller in my navigationcontroller stack because of after navigation i don't want the viewcontroller to be came while back button pressed. So you can easily get that by the following                      self . navigationController ?. removeViewController (My VC . self )

Textfield next option to focus on next textfield in tableview iOS swift

 Problem: I'm having tableview with multiple cells with multiple textfields.I'm having next button option for all textfields and end of textfield will have done option with that. While user click on next we want to focus the next textfield in the tableview. How to achieve that? Solution: First you have to assign row index as tag to the tableview textfield.Then use the below code to achieve that.      func textFieldShouldReturn ( _ textField: UITextField ) -> Bool {         if let nextField = textField. superview ?. viewWithTag (textField. tag + 1 ) as ? UITextField {             nextField. becomeFirstResponder ()         } else { // for end textfield             textField. resignFirstResponder ()          }         return false     }

Hide on section if text is empty and Show the section if text is not empty iOS swift

 Problem: I want to hide one section if my text value is empty.If  my text is not empty then want to show the section with text. How to achieve that? Solution:      func tableView ( _ tableView: UITableView , heightForRowAt indexPath: IndexPath ) -> CGFloat {         switch indexPath. section {          case   mysection :             if text != nil {                 return 82             }             return 0 } }