2

I have an error with my custom UITableViewCell image not showing up until the UITableView is scrolled. It dosnt happen to all of the cells only the next one comming on or the most recent one comming off (for instane if you see half of the cell on the bottom you cannot see the image until you scroll it all the way into view)

So I have decided that maybe I need to do a better job of relating my UIImages to the correct custom cell.

I have created a UIImageView called "firstImageView" I then go into my interface builder and relate that to the correct UIImageView.

Then inside tableview:cellForRowAtIndexPath: I try to set it like this

myCustomCell.firstImageView.image = [UIImage imageNamed:@"SMILE.png"];

However I get this error

Property 'firstImageView' not found on object of type 'UITableViewCell *'

Any help would be appreciated

4 Answers 4

1

To address your error with upcoming images, here is my answer: When you get your UITableViewCell like this

MyCustomCell *myCustomCell = [self.tableView dequeueReusableCellWithIdentifier:@"myCustomCellIdentifier"];

you can implement -(void)prepareForReuse method of your override of UITableViewCell. Otherwise it is also possible to set the custom content in your -(UITableViewCell *)tableView:cellForRowAtIndexPath: method after dequeuing your cell.

You can get further information here: How to use prepareForUse-Method and Apple Documentation of UITableViewCell

To address the other problem with unknown class attribute: What type is your myCustomCell? In the interface builder you have to assign the correct type and your myCustomCell also has to be of the correct type.

8
  • okay thank you.. going to read up more about prepareForUse.. will it matter that I have several different customer tableviewcells
    – HurkNburkS
    Mar 5, 2013 at 22:58
  • For all your custom UITableViewCell classes you use you have to implement this method. It is called when dequeueReusableCellWithIdentifier: is called.
    – who9vy
    Mar 5, 2013 at 22:59
  • This is not true. I've made plenty of projects with custom cells, and never implemented this method. He probably didn't change the class of the cell to his subclass, which is why the error is saying UITableViewCell rather than what ever his class is.
    – rdelmar
    Mar 5, 2013 at 23:58
  • damn I cannot figure it out.. I would love for someone to check out my tableview:cellForRowAtIndexPath: method but I am working on a sensitive project I dont want to post alot of its details on the net...
    – HurkNburkS
    Mar 6, 2013 at 0:17
  • @rdelmar It depends on your cell initialization. When you initialize a cell with [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"someReuseIdentifier"] or with [someTableView dequeueReusableCellWithIdentifier:@"someIdentifier"] makes the difference. In the first case you are initializing a new cell and the reuse identifier is not used. In the latter case you dequeue a cell with a given reuse identifier, thus, a cell is reused and you have to set the new custom content, e.g. a custom image.
    – who9vy
    Mar 6, 2013 at 9:02
1

here 122,111 are THE frames for image view in table view cell replace it with yours `` UIGraphicsBeginImageContextWithOptions(itemSize, NO,UIScreen.mainScreen.scale); ˚˚CGSize itemSize = CGSizeMake(122,111);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[imageView.image drawInRect:imageRect];
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

0

When dequeueing the cell are you casting it as your custom cell class?

MyCustomCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
0

It looks like you created a custom UITableViewCell subclass but you don't dequeue it using the Identifier you assigned in IB ("reuse identifier")..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.