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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:04+00:00 2026-05-23T08:18:04+00:00

I’m having a problem with my current App. It has one UITableView in the

  • 0

I’m having a problem with my current App. It has one UITableView in the UIViewController. I have one UIButton at the bottom (out of the UITableView). It works in that way:

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"bla"]) {
[[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"bla"];
[tableView reloadData]; 
} else {

[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"tasks2do"];
[tableView reloadData]; }

This worked when I had the cell.textLabel.text Method in this way:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    

static NSString *ident = @"indet";

cell = [tableView dequeueReusableCellWithIdentifier:ident];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ident] autorelease];

}

if (![[NSUserDefaults standardUserDefaults] boolForKey:@"bla"]) {

cell.textLabel.text = [firstArray objectAtIndex:indexPath.row]; 

} else {

cell.textLabel.text = [secondArray objectAtIndex:indexPath.row];

}                
return cell; }

Now I want to use an UILabel instead of cell.textLabel, because I need it for some reasons (eg. setting the labels frame)

For that I used the following code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    

static NSString *ident = @"indet";

cell = [tableView dequeueReusableCellWithIdentifier:ident];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:ident] autorelease];
}
UILabel *thislabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 44)] autorelease];

if (![[NSUserDefaults standardUserDefaults] boolForKey:@"bla"]) {

    [thislabel setText:[firstArray objectAtIndex:indexPath.row]];

    } else {

    [thislabel setText:[secondArray objectAtIndex:indexPath.row]];

}   

[cell.contentView addSubview:thislabel];

return cell; }

That works fine, until I push the UIButton for switching. It switches, the cell shows the new text but behind the new text is still the old text as you can see here:

http://d.pr/Rqx2

(the firstArray contains the letter L, the secondArray contains the Letter J, it mixes up both up)

Do you have any idea for solving this problem since I tried some stuff (for example using 2 UILabels for the arrays and hide one)? Would be cool. 🙂

I hope my English is not too bad to understand, my English skills for writing aren’t the best, I’m sorry for that.

If you need further information / code just post it, shouldn’t be a problem.

  • 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-23T08:18:04+00:00Added an answer on May 23, 2026 at 8:18 am

    I recommend you create a UITableViewCell subclass in which you configure the label (set frame and add it as subview in UITableViewCell’s initializer). Add a property for setting the text in the label and write a setter like this for the property:

    - (void)setLabelText:(NSString *)newLabelText 
    {
        if ([self.labelText isEqualToString:newLabelText]) return;
        [labelText autorelease];
        labelText = [newLabelText copy];
    
        self.label.text = labelText;
        [self.label setNeedsDisplay]; // or perhaps [self setNeedsDisplay];
    }
    

    Edit: by the way, the issue you’re dealing with is the caching. You recreate a new label every time a cell comes in view, even if the cell already had a label before. This happens because you initialize an UILabel outside the UITableViewCell initializer (which only should be called once for every cached cell, afterwards it can be retrieved from cache, including all it’s subviews).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.