Resolved what is the best way to create a form

Discussion in 'iOS Programming' started by erdinc27, Jul 24, 2016.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    i want to know in which way do you create a registration form with 7 or 8 inputs and beside an image for example ?

    Do you choose to use an UIScrollView and place the UITextField inside of it ?

    Do you choose to use an UITableView and place the UITextfield inside each cell ?

    Which one is better way ?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    I would definitely use a static TableView with textFields rather than a scrollview with text fields. If you turn off the row separators the user won't tell the difference. The tableview controller will automatically adjust the table view for the keyboard.
     
  3. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011
    #3
    I think so too. But i faced with a problem in that method. For example we have 10 UITextfield in form. The user starts to fill the text fields and scroll the tableview up. So the entered areas will be cleaned because of deque reusable cell. What would be done in such situation ?
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    You must use a STATIC Table View. The cells won't be dequeued in a static table view. You should have IBOutlets for all the UITextFields.

    Initialize the values in all the text fields in viewDidLoad. You need ivars for the values of each text field. Set up an IBAction method from the text fields to the view controller for the valueChanged event. Call this
    - (IBAction)textFieldTextDidChange:(UITextField *)textField In the action method save the text field value to the appropriate ivar.

    You need to look up examples for STATIC table views.
     
  5. albebaubles macrumors regular

    albebaubles

    Joined:
    Feb 9, 2010
    Location:
    Sierras
    #5
    my latest favorite lazy way to handle these are through UIAlertController.addTextFieldWithConfigurationHandler.
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    Well a table view cell is not an alert controller. However, you can have a closure called when the textField changes with this custom cell:

    Code:
    class MyCell: UITableViewCell {
    @IBOutlet weak var myButton: UIButton!
    // This closure is called when the button is tapped
    var buttonTapClosure:((cell:MyCell) -> ())?
    @IBAction func buttonTapped(sender: UIButton) {
       if let closure = buttonTapClosure {
         closure(cell: self)
       }
    }
    
    The closure is set in cellForRowAtIndexPath.
    The button is added to the cell in IB and connected to the IBOutlet and the touch up inside event is connected to the IBAction.
     
  7. albebaubles macrumors regular

    albebaubles

    Joined:
    Feb 9, 2010
    Location:
    Sierras
    #7
    Ha, right -- you suggested a tableview not me. Too much work if you ask me.
     
  8. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #8
    You can make a universal static table view, kinda like a shell. Then just add in the changes that you need for a given form. That's what I do. The template / shell code has all the basic functionality that I need, then just add the specifics needed for a given usage.
     
  9. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011
    #9
    Thank you all guys. I think i will make it with tableView i made some examples and it seem tableview is better way.
     

Share This Page