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

  • Home
  • SEARCH
  • 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 9156151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:43:09+00:00 2026-06-17T12:43:09+00:00

I’m having some problem with UIButton in a UITableViewCell. I have created a custom

  • 0

I’m having some problem with UIButton in a UITableViewCell.
I have created a custom tableviewcell in storyboard, using the prototype cell.
There are two buttons and I have set a tag to them.
The first time the table view is drawn everything is displayed correct, but if I scroll or update the data and call reloadData on tableview, it’s not updated correct.

Code:

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

static NSString *CellIdentifier = @"Moment Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];        
}

NSLog(@"Cell: %@", cell);

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
NSArray *row = [mMoment objectAtIndex:indexPath.row];

UILabel *label;

label = (UILabel *)[cell viewWithTag:101];
label.text = [row objectAtIndex:0];

label = (UILabel *)[cell viewWithTag:102];
label.text = [NSString stringWithFormat:@"Koeff: %@",[row objectAtIndex:2]];


UIButton *button;
NSString *btn_title;

button = (UIButton *)[cell viewWithTag:104];

NSLog(@"Button: %@", button);

[button setTag:1];
btn_title = [NSString stringWithFormat:@"%@", [row objectAtIndex:4]];
[button setTitle:btn_title forState:(UIControlState)UIControlStateNormal];
[button addTarget:self action:@selector(poangButtonClick:event:) forControlEvents:UIControlEventTouchUpInside];

NSLog(@"Row: %d, Poäng: %@", indexPath.row, btn_title);

label = (UILabel *)[cell viewWithTag:103];
label.text = btn_title;

button = (UIButton *)[cell viewWithTag:105];
[button setTag:2];
btn_title = [NSString stringWithFormat:@"%@", [row objectAtIndex:5]];
[button setTitle:btn_title forState:(UIControlState)UIControlStateNormal];
[button addTarget:self action:@selector(poangButtonClick:event:) forControlEvents:UIControlEventTouchUpInside];

return cell;

}

The first time button = (UIButton *)[cell viewWithTag:104]; is called on every visible row, everything is correct, but if I scroll or reload the view, button is nil?
Why? Retrieving a label the same way works, and is displayed correctly.
How can I change the label of the buttons in the cell?

Regards

/Fredrik

  • 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-06-17T12:43:10+00:00Added an answer on June 17, 2026 at 12:43 pm

    A quick guess: I see you are resetting the buttons “tag” value which you use to refere to it. So you cant retrive it (after changing it) anymore with the value 104 (after the first creation it is now 1 and 2)

    [button setTag:1];
    

    so, you wont get it the next time via

    button = (UIButton *)[cell viewWithTag:105];
    

    My assumption is that that the cell does not get deallocated and thus this tag value stays. Maybe this will solve it.

    • 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 have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text

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.