Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating imageView on UIButton within UITableViewCell
    primarykey
    data
    text
    <p>I have custom <code>UITableViewCells</code> (created in interface builder) which are used for a static <code>UITableView</code> which for the sake of argument I will call the <strong>AddUserTableViewController</strong> (i.e. I do not use autoreleased cells as I only have 5 rows).</p> <p>In the top cell (used for the <strong>user name</strong>) I have embedded a <code>UIButton</code> which I use to open an <code>UIActionSheet</code> which in turn allows an <code>UIImagePicker</code> to set an image on the UIButton (i.e. <code>[button.imageView.image = imageFromImagePicker]</code>). The button has a default image (added in IB) which says "add image".</p> <p>The image on the button is set without issue and remains in place even when I navigate to the detail page of any of the table cells with the exception of the <strong>user name</strong> cell which contains the button. When I select this cell the image dissapears and does not reappear once I navigate back to the <strong>AddUserTableViewController</strong> from the "add name" detail view. The "add image" default image, referred to above, is displayed.</p> <p>I have tried many strategies amongst which have been:</p> <p>1) using <code>[self.tableView reloadData]</code>, <code>[button.imageView setNeedsDisplay]</code>, <code>[self.view setNeedsDisplay]</code> in the <code>viewWillAppear</code> method;</p> <p>2) using the above methods in the <code>cellForRowAtIndexPath</code> method;</p> <p>3) using the above methods in the overriden <code>willDisplayCell:forRowAtIndexPath:</code> method;</p> <p>When I place debugging NSLog statements in the program I can see that the <code>button.imageView.image</code> property is still set to the image selected using the <code>UIImagePicker</code> but it is not displayed (the default image from the nib is displayed).</p> <p>As I mentioned above, this only happens if I navigate away from the <strong>AddUserTableViewController</strong> by selecting the <code>UITableViewCell</code> within which the <code>UIButton</code> is embedded. </p> <p>I am currently at a loss as to what to do and would be extremely grateful for any assistance that anyone could offer. I just need to find a way to update the image on the embedded UIButton in the above-mentioned circumstances.</p> <p>I've added the a section of the code from the <code>cellForRowAtIndexPath:</code> method just for illustrative purposes -</p> <pre><code>//populates the personal info section if (section == kPersonalInfoAddSection) { //Covers the add image button and the name adding field if (row == kNameRow) { UILabel *nameLabel = (UILabel *)[nameCell viewWithTag:kMainTextTag]; UILabel *reqLabel = (UILabel *) [nameCell viewWithTag:kSubTextTag]; //UIButton *imageButton = (UIButton *) [nameCell viewWithTag:kImageTag]; if (mainUser.imagePath != nil) { UIImage *img = [UIImage imageWithContentsOfFile:mainUserImagePath]; imageButton.imageView.image = img; [imageButton.imageView setNeedsDisplay]; //[imageButton setNeedsDisplay]; //[nameCell setNeedsDisplay]; NSLog(@"************************** Added the BESPOKE image (%@)to the image button", img); } else { NSLog(@"************************** Added the DEFAULT image (%@)to the image button", addUserImage); imageButton.imageView.image = addUserImage; } UIColor *blackText = [[UIColor alloc] initWithWhite:0 alpha:1]; NSString *firstName; if (mainUser.firstName){ nameLabel.textColor = blackText; firstName = mainUser.firstName; } else { nameLabel.textColor = reqLabel.textColor; firstName = NAME_STRING; } NSString *lastName = (mainUser.lastName)? mainUser.lastName : EMPTY_STRING; NSString *name = [[NSString alloc] initWithFormat:@"%@ %@", firstName, lastName]; nameLabel.text = name; reqLabel.text = REQUIRED_STRING; [blackText release]; return nameCell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload