UA-17470720-3

Jump to content


Photo
- - - - -

Image for cell

cells general

  • Please log in to reply
6 replies to this topic

#1 RLTW96

RLTW96

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 2 posts
Reputation: 0
Neutral

Posted 06 October 2012 - 03:17 PM

I am trying to put an image inside a cell. Reference "Image for Cell" and "Image for category". To set the stage, By clicking on the "Write a Novel" cell (Image for cell image) it opens up a screen for input (Image for category). I have several icons for the Category cell. Ultimately, by selecting a category, I would like to display the icon inside the cell. Please reference "Finished mock-up" for what I want the end result to be.... Make sense?

Attached Files



#2 cometlinear

cometlinear

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 55 posts
  • LocationCalifornia
Reputation: 10
Good

Posted 07 October 2012 - 12:10 PM

The book explains how to do this by subclassing SCCustomCell and using Interface Builder. See the section on web services.
  • Tarek likes this

#3 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 541 posts
  • LocationIreland
Reputation: 134
Popular

Posted 10 October 2012 - 07:24 AM

I'm also struggling with getting an image to appear in a SCCustomCell.

I've followed the Web Services example, and have a Title and Text appearing correctly in the cell but can't get the image to appear. Here's some code:


SCClassDefinition *aboutDefinition =[SCClassDefinition definitionWithClass:[ImageTitleText class] propertyNamesString:@"about:(imagePath;title;text"];
SCArrayOfObjectsSection *aboutObjectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:@"About" items:aboutArray itemsDefinition:aboutDefinition];

aboutObjectsSection.sectionActions.cellForRowAtIndexPath = ^SCCustomCell*(SCArrayOfItemsSection *itemsSection, NSIndexPath *indexPath) {
SCCustomCell *customCell = [SCCustomCell cellWithText:nil objectBindingsString:@"1:imagePath;2:title;3:text" nibName:@"ImageTitleTextTableCell"];
	
	 ImageTitleText *imageTitleText = [itemsSection.items objectAtIndex:[indexPath row]];
	
	 NSLog(@"row:%i path:%@",indexPath.row, imageTitleText.imagePath);
	
	 return customCell;
};

[self.tableViewModel addSection:aboutObjectsSection];

The NSLog gives the correct path to the image as set by:

[[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"]

but no image appears.

What am I doing wrong? What have I missed?

Edited by Dave Guerin, 10 October 2012 - 07:24 AM.

Cheers,

Dave

www.dgapps.ie

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 12 October 2012 - 04:16 AM

Hi Dave,

STV currently automatically fetches images for web services only, since it understands that it's a fully qualified URL (versus regular objects where it could be anything starting from a local path to an embedded binary blip). The correct way to display an image for non web service objects is via the 'willDisplay' cell action:

...
customCell.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
  NSString *imagePath = [cell.boundObject valueForKey:@"imagePath"];
  cell.imageView = ...;  // set your image here
};
...

Hope this helps!

#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 12 October 2012 - 04:19 AM

It's also definitely worth noting here that we should also have STV try to guess your image source for regular objects too. Might be a bit of a performance issue, but it needs to be tested out. Definitely an area for future improvement.

#6 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 541 posts
  • LocationIreland
Reputation: 134
Popular

Posted 12 October 2012 - 08:43 AM

Hi Tarek,

Thanks for the reply.

I had tried appending file:// to the path as I realised that the Web Services example was using the full URL. My ImageTitleText also has a UIImage *image property so this:

aboutObjectsSection.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
	 cell.imageView.image = [cell.boundObject valueForKey:@"image"];
};

works well.

But it only works if I have one section. With additional sections I get images where I shouldn't in the other section, and STV complains:

Warning: Property 'image' does not exist in object '<Help: 0x1e078fe0>

The other section is another SCArrayOfObjectsSection.

Interestingly the indexPath.section is always 0, never the 1 I'd expect for the second section of a table.

Any ideas?
Cheers,

Dave

www.dgapps.ie

#7 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 541 posts
  • LocationIreland
Reputation: 134
Popular

Posted 30 October 2012 - 01:44 AM

For one else confused about adding images to custom cells, there's a bit bit more to the story:

I had a custom cell with the image to the right and couldn't work out why the image was still being displayed on the left using the above code. I eventually realised that I was setting the image of the default imageView that all SCTableViewCell have (I think). So, to set the image of my UIImageView, that had a tag=1, here's the code I used:

aboutArrayOfObjectsSection.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {

/*
		 We need to find our UIImageView that has as tag of 1. It's a subview of
		 a subview of the cell, so iterate through each subview, and for each of
		 those subviews iterate through again. Once we find the view with a tag
		 of 1, and it's a UIImageView, then cast the UIView to a UIImageView,
		 and set it's image to our boundObject image.
		 */
	 for (UIView *subview in cell.subviews) {
		 for (UIView *subSubview in subview.subviews) {
			 if (subSubview.tag == 1 && [subSubview isKindOfClass:[UIImageView class]]) {
					 UIImageView *imageView = (UIImageView*)subSubview;
					 imageView.image = [cell.boundObject valueForKey:@"image"];
					 /*
						 Jump out of our nested for loops to avoid any more
						 iterations. I've not used a goto in maybe 20 years!
						 */
					 goto imageSet;
			 }
		 }
	 }
	 imageSet:; // This is the label that we goto
};

HTH!

This also stopped all the warnings I was getting, and stop images turning up in cells in other sections where they weren't supposed to be.

Someone else might be along in a while to give better code to find the UIImageView with a tag=1, but this code works for me :-)
Cheers,

Dave

www.dgapps.ie





Also tagged with one or more of these keywords: cells, general

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users