Hiding UITableView separator behind the contentView - iphone

I made a grouped UITableView in iPhone OS 3.0 that looked like the left image. The result is the right image in OS 3.1.
The imageView is under the separators.
I've tried to put the content view in front. The separatorStyle propriety seems ignored when the tableView is in grouped style (to draw the separator myself). Changing the separator color gives strings results.
Thanks for your help!
Edit: This is the code with no change made :
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont boldSystemFontOfSize:18.0];
}
cell.textLabel.text = [[metro.arretDirection objectAtIndex:indexPath.row] name];
NSString* name;
if (indexPath.row == 0) {
name = #"Begining";
}
else if (indexPath.row + 1 == [metro.arretDirection count]) {
name = #"End";
}
else {
if ([[[metro.arretDirection objectAtIndex:indexPath.row] lines] count]== 1) name = #"Little";
else name = #"Big";
}
UIImage* metroImage = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[NSString stringWithFormat:#"%i%#.png", metro.metroNumber, name]]];
cell.imageView.image = metroImage;
[metroImage release];
return cell;

On the cell try setting clipsToBounds to NO. eg cell.clipsToBounds = NO;

The answer was actually quite simple, simply add an UIImageView in the cell an place it properly instead of using the built in imageView.

Related

Mixing UITextView and plain Title/Right Detail cells in same iOS iPhone app tableview

I've researched many StackOverflow.com questions, and there seems to be a lot of
confusion over how to get a UITextView displayed into a cell of a Table(View). Here's what
I want: a table where cell rows 0 and 3, for example, are simple Title/Right Detail text cells, and where cells (rows) 1 & 2 have embedded UITextViews that display a clickable phone number and a clickable URL for a website, respectively.
My first attempt set up and allocated UITextView subViews outside of the "if (cell == nil)"
code block:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize infoTableData;
#synthesize infoDetailTableData;
#synthesize cellImages;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.infoTableData = [[NSMutableArray alloc] initWithObjects: #"Address", #"Telephone", #"Website", #"Hours", #"Reservations", #"Parking", #"Takeout", #"Cash only?", nil];
self.cellImages = [[NSMutableArray alloc] initWithObjects:
#"compass_24x24.png",
#"mobilephone2_24x24.png",
#"web_24x24.png",
#"calendar_24x24.png",
#"clock2_24x24.png",
#"parking_meter_24x24.png",
#"shopping_bag_24x24.png",
#"credit_cards_24x24.png", nil];
self.infoDetailTableData = [[NSMutableArray alloc] initWithObjects:
#"123 Main St.",
#"555-555-5555",
#"www.genericrestaurant.com",
#"11:30-2:30,Su:11;5:30-10;F-Sa:10:30,Su:9",
#"Recommended",
#"Parking lot (in rear); on-street",
#"No",
#"Credit cards accepted", nil];
}
#pragma mark Table Source, Delegate Protocol code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.infoTableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ATTEMPT #1: place subView allocate code outside of 'if (cell == nil)' block...
// Causes cell corruption issues upon table scrolling...
static NSString *cellIdentifier = #"DetailInfoCell"; // same ID as used in storyBoard cell setup...
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:14.0f];
cell.textLabel.text = [self.infoTableData objectAtIndex: indexPath.row];
UIImage *cellImage = [UIImage imageNamed:[self.cellImages objectAtIndex:indexPath.row]]; // ditto: cellImages = array of strings
cell.imageView.image = cellImage;
// Add UITextView to cell for phone, website rows
if (indexPath.row == 1 || indexPath.row == 2)
{
cell.detailTextLabel.text = #"";
// Using constants = embarrassing hack -- figure out proper way
UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(cell.frame.origin.x + (cell.frame.size.width)/2.1f,
cell.frame.origin.y + 2.0f,
(cell.frame.size.width)/2.0f,
cell.frame.size.height)];
if (indexPath.row == 1)
tv.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
else
tv.dataDetectorTypes = UIDataDetectorTypeLink;
tv.editable = NO;
tv.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
tv.textAlignment = NSTextAlignmentRight;
//tv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // or use this instead?
tv.contentMode = UIViewContentModeRight;
tv.backgroundColor = [UIColor clearColor];
tv.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
tv.text=[self.infoDetailTableData objectAtIndex: indexPath.row];
[cell.contentView addSubview:tv];
}
else
{
cell.detailTextLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
cell.detailTextLabel.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
}
return cell;
}
#end
But when I scrolled the table, cell contents overwrote each other. After further research on this website, I learned that it's supposedly a big no-no to set up and allocate the UITextView subViews outside of the "if (cell == nil)" block, because when a cell is dequeued for re-use (using "dequeueReusableCellWithIdentifier"), it may already have had a UITextView subView added to it, so UITextView subViews will be added to cells that already have them, which causes cell corruption issues during scrolling.
So my second attempt tried to get around that problem by using tags to keep track of cells:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ATTEMPT #2: put subView allocate block INSIDE 'if (cell == nil)' block
// Now, subViews are blank -- they do not appear in the cell rows (even during scrolling)
static NSString *cellIdentifier = #"DetailInfoCell"; // same ID as used in storyBoard cell setup...
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
UITextView *tv1 = nil;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
// Using constants = embarrassing hack -- figure out proper way
UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(cell.frame.origin.x + (cell.frame.size.width)/2.1f,
cell.frame.origin.y + 2.0f,
(cell.frame.size.width)/2.0f,
cell.frame.size.height)];
tv.tag = indexPath.row; // keep track of this cell, for later re-use...
if (indexPath.row == 1)
tv.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
else
tv.dataDetectorTypes = UIDataDetectorTypeLink;
tv.editable = NO;
tv.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
tv.textAlignment = NSTextAlignmentRight;
//tv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // or use this instead?
tv.contentMode = UIViewContentModeRight;
tv.backgroundColor = [UIColor clearColor];
tv.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
tv.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
[cell.contentView addSubview:tv];
}
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:14.0f];
cell.textLabel.text = [self.infoTableData objectAtIndex: indexPath.row]; // infoTableData = data source array of strings...
if (indexPath.row == 1 || indexPath.row == 2)
{
cell.detailTextLabel.text = #"";
tv1 = (UITextView *)[cell.contentView viewWithTag: indexPath.row]; // get pointer to 'correct' re-usable cell...
tv1.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
}
else
{
cell.detailTextLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
cell.detailTextLabel.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
}
return cell;
}
This second attempt failed. The UITextViews weren't showing up at all. The cell
"detail text areas" were blank.
Yet more research on this site revealed postings which claimed that you had to clear any
subViews on returned cells from the call to [tableView dequeueReusableCellWithIdentifier...],
so that adding a new UITextView subView to the cell wouldn't cause problems. So my third
attempt tried this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ATTEMPT #3: keep subView allocate code INSIDE 'if (cell == nil)' block; try to clear subViews from cells
// Still does not work: subViews still blank
static NSString *cellIdentifier = #"DetailInfoCell"; // same ID as used in storyBoard cell setup...
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
UITextView *tv1 = nil;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
// Using constants = embarrassing hack -- figure out proper way
UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(cell.frame.origin.x + (cell.frame.size.width)/2.1f,
cell.frame.origin.y + 2.0f,
(cell.frame.size.width)/2.0f,
cell.frame.size.height)];
tv.tag = indexPath.row; // keep track of this cell, for later re-use...
if (indexPath.row == 1)
tv.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
else
tv.dataDetectorTypes = UIDataDetectorTypeLink;
tv.editable = NO;
tv.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
tv.textAlignment = NSTextAlignmentRight;
//tv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // or use this instead?
tv.contentMode = UIViewContentModeRight;
tv.backgroundColor = [UIColor clearColor];
tv.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
tv.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
[cell.contentView addSubview:tv];
}
else
{
// Clear subviews, if any?
// Tried this: did not work: subViews still blank
[[[cell contentView] subviews] makeObjectsPerformSelector: #selector(removeFromSuperview)];
// Tried this: did not work: subViews still blank
for (UIView *view in cell.contentView.subviews)
{
if ([view isKindOfClass:[UIView class]])
{
[view removeFromSuperview];
}
}
}
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:14.0f];
cell.textLabel.text = [self.infoTableData objectAtIndex: indexPath.row]; // infoTableData = data source array of strings...
if (indexPath.row == 1 || indexPath.row == 2)
{
cell.detailTextLabel.text = #"";
tv1 = (UITextView *)[cell.contentView viewWithTag: indexPath.row]; // get pointer to 'correct' re-usable cell...
tv1.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
}
else
{
cell.detailTextLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
cell.detailTextLabel.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
}
return cell;
}
This had no affect whatsoever. UITextView subViews were still not appearing in the cells.
Yet even more research. Yet another posting said that:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
will always return a cell in iOS6, so that code within the "if (cell == nil)" block
will never even execute -- the returned cell will never be nil. Sure enough, that's
what I found out: no breakpoint was ever being reached inside my "if (cell == nil)"
code block -- the code was never being executed.
My fourth attempt was just to add a "magic" line of code that yet another posting
suggested:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
which I'm guessing roughly translates to: "always return a new cell, not a used
one, and don't worry about performance or memory issues" (I sense the internet-sphere rolling its eyes at about this point), and sure enough, that did the trick, once I removed the UITextView allocate/setup code from within the "if (cell == nil)" and put it back where it was originally (outside the block, so that it always executes).
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ATTEMPT #4:
// According to one particular posting on StackOverflow.com, 'dequeueReusableCellWithIdentifier' will
// *always* return a cell in iOS6 and above. Go figure... Use 'nil' for cell id on
// dequeueReusableCellWithIdentifier
// For some reason, this works...
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
}
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:14.0f];
cell.textLabel.text = [self.infoTableData objectAtIndex: indexPath.row];
UIImage *cellImage = [UIImage imageNamed:[self.cellImages objectAtIndex:indexPath.row]];
cell.imageView.image = cellImage;
if (indexPath.row == 1 || indexPath.row == 2)
{
cell.detailTextLabel.text = #"";
UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(cell.frame.origin.x + (cell.frame.size.width)/2.1f,
cell.frame.origin.y + 2.0f,
(cell.frame.size.width)/2.0f,
cell.frame.size.height)];
if (indexPath.row == 1)
tv.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
else if (indexPath.row == 2)
tv.dataDetectorTypes = UIDataDetectorTypeLink;
tv.editable = NO;
tv.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
tv.textAlignment = NSTextAlignmentRight;
//tv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // or use this instead?
tv.contentMode = UIViewContentModeRight;
tv.backgroundColor = [UIColor clearColor];
tv.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
tv.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
[cell.contentView addSubview:tv];
}
else
{
cell.detailTextLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
cell.detailTextLabel.text = [self.infoDetailTableData objectAtIndex: indexPath.row];
}
return cell;
}
But this seems to be a hack. Can someone post some very simple, basic iPhone
app code (I guess for iOS6/4S or equivalent, but does it really matter?) that
represents the canonical, proper way to fill a TableView so that some rows
are simple Title/Right Detail "text-only" cells, and some cells are UITextView
subView cells with phone numbers/website links in the "details" section? Am
I required to subClass a UITableViewCell or use some "prepareForReuse"
method?
Note: I'm using a storyBoard to set up one, Dynamic Prototype cell, with an
identifier 'string'.

cell.textLabel not getting resized

I'm trying to create a Settings for our app. I'm not sure what is happening here. I have a UITableViewSyleGrouped and in each section of the table, there is 1 row. For my particular row, it shows the person's name. If you click on it, then it pushes to a new tableView that has the list of people to choose from, then when you pop back, the label gets updated, but the label is truncated when I go from a smaller name to a bigger name. I'm trying to create a Settings for our app. Some of the fields look like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (tableView == _settingsTableView) {
UITableViewCell *cell = nil;
NSNumber *aSection = [_tableArray objectAtIndex:indexPath.section];
if ([aSection integerValue] == SOUNDS)
{
cell = [tableView dequeueReusableCellWithIdentifier:#"SwitchCell"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"SwitchCell"] autorelease];
}
cell.textLabel.text = #"Sounds";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = switchView;
[switchView setOn:[[Settings sharedInstance] playSounds] animated:NO]; // initialize value from Settings
[switchView addTarget:self action:#selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[switchView release];
}
else if ([aSection integerValue] == PERSON) {
cell = [tableView dequeueReusableCellWithIdentifier:#"PersonCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:#"PersonCell"] autorelease];
}
Person *p = [_personArray objectAtIndex:row];
cell.textLabel.text = [NSString stringWithFormat:#"%# %#", p.firstName, p.lastName];
NSLog(#"cL: %#", NSStringFromCGRect(cell.textLabel.frame));
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
My PERSON section gives the user the ability to change People. That code in didSelectRowAtIndexPath is
else {
Person *p = [_personArray objectAtIndex:row];
NSUInteger oldRow = [_lastIndexPath row];
if (oldRow != row) {
dmgr.currentPerson = p;
// Put checkmark on newly selected cell
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
// Remove checkmark on old cell
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:_lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
[_settingsTableView deselectRowAtIndexPath:_lastIndexPath animated:YES];
self.LastIndexPath = indexPath;
// Update the cell
NSIndexPath *path = [NSIndexPath indexPathForRow:0 PERSON];
UITableViewCell *theCell = [_settingsTableView path];
theCell.textLabel.text = [NSString stringWithFormat:#"%# %#", p.firstName, p.lastName];
[theCell setNeedsDisplay];
NSLog(#"ceLL: %#", NSStringFromCGRect(theCell.textLabel.frame));
}
}
What happens is the label is truncated until I click on the label. (e.g. John D... instead of John Doe). Why does the label not get updated?
I tried looking at the frames, and I'm not sure if that has something to do with it or not. My output is:
cL: {{0, 0}, {0, 0}}
ceLL: {{10, 11}, {76, 21}}
The textLabel field of a UITableViewCell is a regular UILabel. You can set this property to cause it to scale down the text to fit:
theCell.textLabel.adjustsFontSizeToFitWidth = YES;
You can also set a minimum font size
theCell.textLabel.minimumFontSize = whatever
Take a look at the Documentation on UILabel it will help you a lot.

How to avoid over ride of labels which are added to cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 33)];
dataLabel = [[UILabel alloc]initWithFrame:CGRectMake(105, 0, 320, 33)];
timeLabel.backgroundColor = [UIColor clearColor];
dataLabel.backgroundColor = [UIColor clearColor];
dataLabel.textColor = [UIColor whiteColor];
timeLabel.textColor = [UIColor whiteColor];
[cell.contentView addSubview:timeLabel];
[cell.contentView addSubview:dataLabel];
if(indexPath.row == 0)
{
if([storedDataArray count]>0)
{
timeLabel.text = currenttime;
dataLabel.text = textView1.text;
}
return cell; //returns empty cell if there is no data in the data base
}
if(indexPath.row == 1)
{
timeLabel.text = currenttime;
dataLabel.text = textView2.text;
return cell;
}
I have a table view
- i want to display my textlabel on left side, just beside detailTextlabel.
actually when i use textLabel.text, DetailTextLabel.Text and alignments,
they displayed but not at the position i want.
so i tried to use own labels..
but they get overwritten.
since we did not (it's not possible to) change the possition & the frame size of the cell textlabel, detailTextLabel, i added 2 labels with a frame size that i want.
but when we entered text in text views and return back to table view.. the labels get overwritten..
what to do..
is there any alternate to fixed the frame size of my text label
or to avoid overwriting of our labels
Use Custom UITableViewCell instead. You can align and place labels easily using custom tabe cells.
This link will be helpful. http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1
look at the customizing section in the document.
use this code it will work perfectly
if (cell== nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"MenuNameCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
NSLog(#"---------new cell agin");
}
else
{
NSArray *arrayView = [cell.contentView subviews];
for (UIView *vTemp in arrayView)
{
[vTemp removeFromSuperview];
}
NSLog(#"---No New Cell hiiii");
// Setting Tag To UIButton
_checkButton = (UIButton *)[cell.contentView viewWithTag:indexPath.row];
_cancelButton = (UIButton *)[cell.contentView viewWithTag:indexPath.row];
}
add else part only

Why isn't my CustomCell class displaying properly?

Hey all, I'm trying to create a business finder style app and was hoping to create a custom cell to display some information to the user. I've got the cell to display all the information I'm trying to give, but the format is off. Here is the code I'm using to create the cell.
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCellView" owner:self options:nil];
#ifdef __IPHONE_2_1
cell = (CustomCell *)[nib objectAtIndex:0];
#else
cell = (CustomCell *)[nib objectAtIndex:1];
#endif
}
// Configure the cell.
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
cell.bizNameLabel.text = [dict objectForKey:#"name"];
cell.addressLabel.text = [dict objectForKey:#"address"];
NSMutableString *detailed = [NSMutableString string];
[detailed appendString:[dict objectForKey:#"distance"]];
[detailed appendString:#"mi"];
cell.mileageLabel.text = detailed;
// determine the rating for the business
NSString *icontype = [dict objectForKey:#"rating"];
NSInteger rating = [icontype intValue];
UIImage *image;
// variable to change the color of the cell's background
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
// switch statement to determine the rating image to be displayed
switch (rating) {
case 1:
{
image = [UIImage imageNamed:#"1.png"];
bg.backgroundColor = [UIColor yellowColor];
break;
}
case 3:
{
image = [UIImage imageNamed:#"3.png"];
bg.backgroundColor = [UIColor orangeColor];
break;
}
case 5:
{
image = [UIImage imageNamed:#"5.png"];
//bg.backgroundColor = [UIColor redColor];
cell.backgroundColor = [UIColor redColor];
break;
}
default:
break;
}
[cell.ratingImage setImage:image];
cell.backgroundView = bg;
[bg release];
#ifdef __IPHONE_3_0
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
#endif
return cell;
}
I then created the layout in IB to look like this..
(First 2 issues have been resolved, I was using the wrong image variable to display the image)
And when selected, you can tell things are out of whack
![enter image description here][3]
In IB I have the dimensions of the cell set at 320wide by 80high, and under the indentity tab, I've changed the class to CustomClass. I'm sure I'm overlooking something trivial, but if someone could throw me a bone, I'd be grateful. I've fixed the problem I was having with the image not displaying where I wanted it to, but I'm still having issues with the background color not changing, font size displaying different and when the cell is selected, it overlaps the cell separator.
Note: tried to include screen shots, but since I'm new SO wouldn't let me. I've provided a link where I've put the image of the selected cell that overlaps the separator below.
http://s1216.photobucket.com/albums/dd361/cabearsfan/?action=view&current=screenshot2.png
Seems like you are not using your nib reference of the UIImageView but you are using the default imageView property of the cell.
I'd say there is a mis-match between the imageview frame and the size of the image you're giving it.
After your setImage call, add this code to find out what's going on:
NSLog(#" imageView frame %f,%f, %f, %f",imageView.frame.origin.x,imageView.frame.origin.y,
imageView.frame.size.width,imageView.frame.size.height);
NSLog(#" image size %f x %f", image.size.width, image.size.height);

iPhone Admob UITableView troubles

I am sure this is a simple fix, but I can't seem to find it. I have a table view that currently works just fine, set up as:
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [creedsList objectAtIndex:row];
cell.imageView.image = [UIImage imageNamed:[creedsImages objectAtIndex:row]];
return cell;
The Admob SDK says to add this line:
[cell.contentView addSubview:[AdMobView requestAdWithDelegate:self]];
But then it populates EVERY cell with ads. Any thoughts?
EDIT:
I am using this code to populate:
NSUInteger row = [indexPath row];
cell.textLabel.text = [creedsList objectAtIndex:row];
You want to do that on only the particular rows you want the ads to show up in.
So if you wanted to show up only on the first row, you could do something like
static int adTag = 999; // Used for identifying whether cell already contains ad
UIView * adView = [cell.contentView viewWithTag:adTag];
if(row == 0 && !adView)
{
adView = [AdMobView requestAdWithDelegate:self];
adView.tag = adTag;
[cell.contentView addSubview:adView];
}
else if(row != 0 && adView)
{
// Must remove since cells are reused.
[adView removeFromSuperview];
}