ImageView on tableViewCell doesnt appear? - iphone

I have a tableView and you can add cells. and it doesnt show my image on the left hand side of the newly added cells. I'm using the default cell style and here is my code:
This is the button that allows us to add a cell.
- (IBAction)outlet1:(id)sender {
[cart.cells addObject:#"1"];
cart.cell.imageView.image = [UIImage imageNamed:#"paddle1.png"];
}
Please help! I checked the name of the image and it seems good. Thanks!

It would be better to place the image to the UITableViewCell inside the cellForRowAtIndexPath method, by setting the image to cell.imageView.image

Related

how do i achieve this in TableViewCell

see below figure, it has- TableView & tablecell have same background image i.e.tableview & tablecell must not look different. in tableCell there must be one button .
To achieve this you'll have to create a customized UITableViewCell.
You'll required 4 background image for your cell.
a. Image Facing right. b. Rollover image facing right. c.
Image Facing left. d. Rollover image facing left.
You'll have to set alternate image to your cell. And when you click on the cell you'll need to change the background image of that particular cell to Rollover image.
Also you'll have to manage the frames of your rest of the control accordingly.
This is nothing but the image. You have to set an image in every tableviewcell by passing the condition
if(indexpath.row/2 == 0)
<set_image1>
else
<set_image2>
then adjust other parameters according to your desired frame position.
Note: You need to use dynamic tableviewcell height &
You need for images for this.Two when cell is not selected & rest two when cell got selected
Enjoy Programming!
I did this following way:
I created two prototype cells having different Cell identifier
e.g. left cell identifier= Cell1 & right cell identifier=Cell2.
simply put one round-rect button, make it as custom because it shows only in image shape
made table cell background color as clearColor, it requires because for the feel of table cell & tableview must look same.
also set tableView background color as clearColor & add images to both button.
if ((indexPath.row)%2!=0)
{
CellIdentifier=#"Cell1";
}
else
{
CellIdentifier=#"Cell2";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIButton *topicButton=(UIButton *)[cell viewWithTag:1];
NSString *topicNameLabel=[_topics objectAtIndex:indexPath.row];

Table View cell image dissappear and reappear on selection

I have a custom UITableViewCell class. I am toggling between accessoryTypes of UITableViewCellAccessoryCheckmark and UITableViewCellAccessoryNone when didSelectRowAtIndexPath is called. Here's an example of what the cells look like before and after selection:
before...
after....
My problem is this: the circle-colored views on the left hand side flicker when I select the cell. How do I keep the circles from flickering when the table cell is selected? I'm not manually doing any sort of reloading of the cell. Does it have something to do with selection state? Any help would be greatly appreciated; thanks!
I assume that in your cellForRowAtIndexPath method you are doing something like
[cell setImage:[UIImage imageNamed:#"someImage"] forState:UIControlStateNormal];
Try setting an image for UIControlStateHighlighted and see if that helps. Even if its the same image.
Yep, that was the solution. Thanks #aking63 for spiking an idea in me. By just overriding the setSelected method in my custom UITableViewCell class, and populating the indicator view the same way I was on setting up the cell, all things work as needed. No more flicker!

iphone UITableView Custom Cell selected image

I have a custom UITableViewCell which fills the cell with a background PNG and a label.
When the user selected the cell, I wish to have the back ground change for an instant to visually give them indication that the row was selected. Similar to the default behavior when a custom cell is not used.
How is that done?
You can try this tutorial:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Posting as answer so this is correct (originally from BahaiResearch.com):
In this scenario the correct answer is to use the following, when setting the image originally:
image.HighlightedImage = [UIImage ..];
Otherwise you are loading images when the highlight event occurs and in theory there's a slight delay, etc.
let me clear first do you wish to change the backgroundimage.png??
if yes and you are using UIImageView for that then you can write following code in rowDidSelected event..
UIImageView *myImageView = [Cell viewWithTag:1]; //Tag is given in Interface Builder for the ImageView
myImageView.image = [[UIImage alloc] imageNamed:#"newimage.png"];

UIImageView in UITableCell gets a weird size

I'm trying to place a UIImageView in a UITableViewCell.
I create a special view called ProductView. In that view, I have several components, one of them being a UIImageView. I set this ProductView as content view of the UITableViewCell. Everything is drawn properly except the UIImageView. UIImageView gets scaled meaninglessly. It's height gets twice the height of the table cell size.
I've spent hours trying to solve this problem. I've set the frame of UIImageView manually, I've called drawRect method of UIImage in UIImageView, neither of them worked.
I'm thinking of replacing UITableView with a UIScrollView if I can't find a solution. Does anyone know how to solve this problem?
Use the Custom cells, and place all the UI component inside that cell, (including the UIImageView), and in cellForRowAtIndexPath method, set the image like following:
[cell.imgView setContentMode:UIViewContentModeScaleAspectFit];
[cell.imgView setFrame:CGRectMake(cell.imgView.frame.origin.x, cell.imgView.frame.origin.y, 120, 79)];
[cell.imgView setImage:[UIImage imageNamed:#"image.png"]];
And if you need to know how to use custom cells, follow this tutorial :
iPhone Programming Tutorial: Part 6: Creating custom UITableViewCell Using Interface Builder [UITableView]
Hope this helps you...
I've had the same problem and realized in the end that the issue wasn't anything to do with automatic resizing, it was simply that I was not getting the UIImageView, but its parent view (the table cell), due to clashing tag values (I was getting the view through callUIImageView *pictureView = (UIImageView *)[cell viewWithTag:0]; and tag zero was also set on the cell). Fixed by just changing the tag value.

Resizing UITableViewCell when entering edit mode

I have a cell that I have designed in Interface Builder, and when I enter edit mode, it moves the whole cell to the right to make space for the delete icon, but it pushes all items to the right, not shrink them down. It pushes a UILabel off of the edge of the cell. Also, this is over the move handles. How do I shrink these items down, instead of just moving them.
I've never made a custom tableview cell in Interface Builder. So, I don't know how to solve your problem on Interface Builder.
But if you programmatically add all items into the contentView property of UITableViewCell instead of adding these into UITableViewCell itself, these items would automatically shrink when entering edit mode.
I have a partial solution.
On the custom cell object I've created a IBOutlet to the view that holds all subviews in the cell (myContentView).
This way I can run this code to shrink it:
OrderReviewCell * cell = (OrderReviewCell * )[reviewTable cellForRowAtIndexPath:indexPath];
CGRect frame = cell.myContentView.frame;
frame.size.width = 200;
cell.myContentView.frame = frame;
I've figured that the best place to put this is in shouldIndentWhileEditingRowAtIndexPath but my problem is Where to put the code that returns the cell to its normal state?
Hope it helps and DO let me know when you find the right answer!
Gonso