Adding an image to a cell


#1

Is there a way for me to an image to a cell without creating a custom cell? I’ve attempted to add right to the cell using addSubview: but it puts the image in multiple places.

I don’t see a bare bones documents for adding something as simple as an image. Even the github projects/demos on weather use datasources and lots of custom cells.


#2

Greetings Program!

stuart little

I’ve attempted to add right to the cell using addSubview: but it puts the image in multiple places.

This sound like what happens when the cell is reused.

Using the GettingStarted sample app, I did the following which works for me:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell
{
	// You will have set the tag (further down) and we will check for the existence of the 
	// image view in the cell and remove it before configuring the cell.
	UIImageView *image = (UIImageView *)[cell viewWithTag:99];
	if (image != nil) [image removeFromSuperview];

	// If you really wanted to, you could throw it in an if statement and only
	// remove it if it's not in the same column.
	// if (![cell.coordinate.column.title isEqualToString:@"Name"]) { [above code] }
	
	[code removed]

    // determine which column this cell belongs to
    if ([cell.coordinate.column.title isEqualToString:@"Name"])
    {
		UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"graphic1.png"]];
		image.frame = CGRectMake(0.0, 0.0, 50.0, 50.0);
		image.tag = 99; // Don't forget to give it a tag number.
		[cell addSubview:image];

        // render the name in the 'name' column
        textCell.textField.text = person.forename;
    }

	
	[code removed]
}

Wg


#3

Thank you very much that helped wonderfully!

For future users you will need to create the imageviews each time as per the example above, you cannot create them once in viewDidLoad and try and reuse because you will only get one of each then.


#4

Any ideas on this one wizgod!? http://www.shinobicontrols.com/forum/shinobicontrols/2014/3/how-to-show-scrollbars-permanently