login using UITableView

How can I create a login for username/password just like in the skype application? I know it’s a grouped table view.. but how can I do that?

I searched the site and found the following code:

  • Exporting customized UITableViewCells into UIImage
  • When does UITableView content size update with row insert/delete animation
  • UITableView Showing last value of a loop
  • How to resize a cell.imageView in a TableView and apply tintColor in Swift
  • Push a new view when a cell is tapped in Table View
  • cannot set background color of UITableViewCell in iOS6?
  •  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            UILabel *startDtLbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 80, 25)];
            if (indexPath.row == 0)
                startDtLbl.text = @"Username";
            else {
                startDtLbl.text = @"Password";
            startDtLbl.backgroundColor = [UIColor clearColor];
            [cell.contentView addSubview:startDtLbl];
            UITextField *passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(100, 5, 200, 35)];
            passwordTF.delegate = self;
            if (indexPath.row == 0)
                passwordTF.tag = 0;
            else {
                passwordTF.tag = 1;
            [cell.contentView addSubview:passwordTF];
        return cell;

    When I do:

    NSString * username = [((UITextField*)[self.view viewWithTag:0]) text];
    NSString * password = [((UITextField*)[self.view viewWithTag:1]) text];

    it gives me this error:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView text]: unrecognized selector sent to instance 0x6c3c600

    Why is this?

    2 Solutions Collect From Internet About “login using UITableView”

    You also have to set:

    tableView.dataSource = self;

    After you assign your view controller as the UITextField delegate, you can access the values of the text fields at various points using the delegate methods below:

    – textFieldShouldBeginEditing:
    – textFieldDidBeginEditing:
    – textFieldShouldEndEditing:
    – textFieldDidEndEditing:

    As an example, in any of these methods, you can grab the textField.text value and assign it to an NSString that can be passed to your LOGIN method as required.

    Suppose your login text field has a tag value of 1 and your password text field has a tag value of 2, you could grab the values using the delegate method below:

    - (void) textFieldDidEndEditing:(UITextField *)textField {
      switch (textField.tag) {
          case 1:
          loginString = textField.text;
          case 2:
          passwordString = textField.text;

    You could also grab references of the corresponding cell and indexPath in any of the methods above by using:

    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell*)[[textField superview] superview]];

    And then to the cell with:

    UITableViewCell *cell = (UITableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];

    These would be particularly useful if you had a long form and want to scroll to the next field so the keyboard is not on top of the cells where you need to type. You can also use these references to make the RETURN key in your keyboard move to the next UITextField or perhaps resign first responder if the user has finished editing the last field of the form.

    I hope it makes sense.