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 7494071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:18:14+00:00 2026-05-29T17:18:14+00:00

I’ve created a custom cell with a textField but I’m not able to retrieve

  • 0

I’ve created a custom cell with a textField but I’m not able to retrieve its value.
In my tableView, there are 3 of these custom cells, together with other default cells.
When I try this:

NSString *string = customCell.textField.text;

I always get a null value…
This is my code:

TextFieldCell.m

#import "TextFieldCell.h"

@implementation TextFieldCell

@synthesize label;
@synthesize textField;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        label = [[UILabel alloc] initWithFrame:CGRectZero];
        label.backgroundColor = [UIColor clearColor];
        label.textAlignment = UITextAlignmentRight;
        label.textColor = [UIColor blackColor];
        label.font = [UIFont boldSystemFontOfSize:16.0];
        label.adjustsFontSizeToFitWidth = YES;
        label.baselineAdjustment = UIBaselineAdjustmentNone;
        label.numberOfLines = 20;
        [self.contentView addSubview:label];

        textField = [[UITextField alloc] initWithFrame:CGRectZero];
        textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        textField.backgroundColor = [UIColor clearColor];
        textField.font = [UIFont boldSystemFontOfSize:16.0];
        textField.delegate = self;
        textField.returnKeyType = UIReturnKeyDone;
        [self.contentView addSubview:textField];
    }

    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];

    CGRect r = CGRectInset(self.contentView.bounds, 8, 8);
    CGRect r1 = CGRectInset(self.contentView.bounds, 8, 8);

    if (label.text != nil)
    {
        r.size = CGSizeMake(12, 27);
        label.frame = r;

        r1.origin.x += self.label.frame.size.width + 6;
        r1.size.width -= self.label.frame.size.width + 6;
        textField.frame = r1;
    }
    else
    {
        textField.frame = r;
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)aTextField
{
    [textField resignFirstResponder];
    return NO;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end

Table View Data Source

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            return [self textFieldCellForTableView:tableView atIndexPath:indexPath];
        }
        else if (indexPath.row == 1)
        {
            return [self textFieldCellForTableView:tableView atIndexPath:indexPath];
        }
        else
        {
            return [self defaultCellForTableView:tableView atIndexPath:indexPath];
        }
    }
    else if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            return [self textFieldCellForTableView:tableView atIndexPath:indexPath];
        }
        else
        {
            return [self defaultCellForTableView:tableView atIndexPath:indexPath];
        }
    }
    else if (indexPath.section == 2)
    {
        return [self defaultCellForTableView:tableView atIndexPath:indexPath];
    }
    else
    {
        return [self chooseFotoCellForTableView:tableView atIndexPath:indexPath];
    }
}

-(TextFieldCell *)textFieldCellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath
{
    static NSString *TextFieldCellIdentifier = @"TextFieldCellIdentifier";

    TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:TextFieldCellIdentifier];
    if (cell == nil)
    {
        cell = [[[TextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TextFieldCellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            cell.label.text = nil;
            cell.textField.placeholder = NSLocalizedString(@"Nome", @"");
        }
        else
        {
            cell.label.text = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencySymbol];
            cell.textField.placeholder = NSLocalizedString(@"Costo", @"");
        }
    }
    else
    {
        cell.label.text = nil;
        cell.textField.placeholder = NSLocalizedString(@"URL", @"");
    }

    return cell;
}

Code To Retrieve TextField Value

TextFieldCell *nomeCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
TextFieldCell *costoCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
TextFieldCell *linkCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];

NSLog(@"nomeCell textField = %@", nomeCell.textField.text);
NSLog(@"costoCell textField = %@", costoCell.textField.text);
NSLog(@"linkCell textField = %@", linkCell.textField.text);

I tried to log nomeCell, costoCell and linkCell and they are correctly allocated and initialized and I’m not using ARC here…
Can anyone help me?
Thank you so much!

  • 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-29T17:18:16+00:00Added an answer on May 29, 2026 at 5:18 pm

    I assume that you have actually entered some text in the text field by the time you are trying to retrieve the values, and you are retrieving the values to update your data model rather than relying on the table view / cells to store your data?

    Don’t obtain the current cell by calling your table view controller’s tableView:cellForRowAtIndexPath:. This should only be called by the table view when it needs a new cell.

    Call the cellForRowAtIndexPath: method on the table view directly. Instead of this:

    TextFieldCell *nomeCell = (TextFieldCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    

    Do this:

    TextFieldCell *nomeCell = (TextFieldCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.