Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5997019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:12:12+00:00 2026-05-23T00:12:12+00:00

I found some example code of how to implement a textfield into a cell

  • 0

I found some example code of how to implement a textfield into a cell here:
Having a UITextField in a UITableViewCell

However the textfield appears multiple times on my table in the 1st section of the table, even though i specified it to only appear when it comes up to the 2nd section of the table and the first row of that section.

Any explanations why this happens? I only want it in the 2nd section 1 st row. but it appears to think that whenever the 2nd section is coming up it will just draw the textfield in advance. Is there a way to “lock” it to a particular group and cell?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [self CreateMultilinesCell:CellIdentifier];
}
NSLog(@"%d", [indexPath section]);
if ([indexPath section] == 1) {
    NSLog(@"TextField");

    if ([indexPath row] == 0 ) {
        UITextField *replyTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 185, 30)];
        replyTextField.adjustsFontSizeToFitWidth = YES;
        replyTextField.textColor = [UIColor blackColor];

        replyTextField.keyboardType = UIKeyboardTypeDefault;
        replyTextField.returnKeyType = UIReturnKeyDone;
        replyTextField.backgroundColor = [UIColor grayColor];
        replyTextField.autocorrectionType = UITextAutocorrectionTypeNo; 
        replyTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        replyTextField.textAlignment = UITextAlignmentLeft;
        replyTextField.tag = 0;
        replyTextField.delegate = self;

        replyTextField.clearButtonMode = UITextFieldViewModeNever;
        [replyTextField setEnabled: YES];

        [cell.contentView addSubview:replyTextField];

        [replyTextField release];
        cell.detailTextLabel.text = @"something";

    }
}
else {
    cell.detailTextLabel.text = [separatedString objectAtIndex:indexPath.row];
}

return cell;
}

createmultilinecell:

- (UITableViewCell*) CreateMultilinesCell :(NSString*)cellIdentifier
{
//NSLog(@"Entering CreateMultilinesCell");
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                                reuseIdentifier:cellIdentifier] autorelease];

cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.font = [self SubFont];
cell.detailTextLabel.textColor = [UIColor colorWithRed:10.0/255 green:10.0/255 blue:33.0/255 alpha:1.0];
[cell setBackgroundColor:[UIColor clearColor]];//]colorWithRed:.98 green:.98 blue:.99 alpha:1.0]];
[self.tableView setBackgroundColor:[UIColor clearColor]];//colorWithRed:.94 green:.96 blue:.99 alpha:1.0]];
                                                         //NSLog(@"Exiting CreateMultilinesCell");
return cell;
}

argh i’m too low to answer my own question so i’ll just update here:

Looks like making 2 cellidentifiers work. Thanks. Just learnt something new! haha.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
NSString *replyCellIdentifier = @"replyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITextField *replyTextField;
if (cell == nil) {
    if ([indexPath section] == 0) {
        cell = [self CreateMultilinesCell:CellIdentifier];      
    }
    else if ([indexPath section] == 1) {
        NSLog(@"TextField");
        cell = [self CreateMultilinesCell:replyCellIdentifier];     
        if ([indexPath row] == 0) {
            replyTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 185, 30)];
            replyTextField.adjustsFontSizeToFitWidth = YES;
            replyTextField.textColor = [UIColor blackColor];
            replyTextField.keyboardType = UIKeyboardTypeDefault;
            replyTextField.returnKeyType = UIReturnKeyDone;
            replyTextField.backgroundColor = [UIColor grayColor];
            replyTextField.autocorrectionType = UITextAutocorrectionTypeNo; 
            replyTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
            replyTextField.textAlignment = UITextAlignmentLeft;
            replyTextField.tag = 0;
            replyTextField.delegate = self;

            replyTextField.clearButtonMode = UITextFieldViewModeNever;
            [replyTextField setEnabled: YES];

            [cell.contentView addSubview:replyTextField];

            [replyTextField release];
            cell.detailTextLabel.text = @"something";
        }           
    }
    /*else {
        cell.detailTextLabel.text = [separatedString objectAtIndex:indexPath.row];
    }*/
}
NSLog(@"%d", [indexPath section]);
if ([indexPath section] == 0) {
    cell.detailTextLabel.text = [separatedString objectAtIndex:indexPath.row];

}
return cell;
}

thanks to everyone that contributed.

In terms of functionality i’m not so sure yet but it’s one step closer to getting where i want it to be :).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:12:13+00:00Added an answer on May 23, 2026 at 12:12 am

    Try having two different cells, one with a textField and one without. Use different CellIdentifier strings for the two different types of cells. That should resolve it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
I found some code in a project which looks like that : int main(int
I have found some in the Cappuccino website (vim, textmate and SubEthaEdit), but not
I have found some libraries or web services in PHP that does the job.
I have found some info on the subject ( like this link) , but
After googling a bit I have found some tips about how to get online
Quick question regarding CSS and the browser. I tried searching SO and found some
I've been parsing through some log files and I've found that some of the
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I've found that on some occasions I can edit the source while debugging. Are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.