UITableView custom section header appears below the cells - iphone

I've a custom section header in my UITableView and I can't figure out why they are appearing bellow the UITableViewCell of the table. See the screenshots:
This is the code that creates the section header:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
return [LojaInfoHeaderView lojaInfoHeaderForSection:section withTitle:sectionTitle opened:[self sectionIsOpen:section] andDelegate:self];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return [LojaInfoHeaderView viewHeight];
}
And the section's cell are inserted or deleted when the user touches the section header:
- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidOpen:(NSInteger)section {
NSArray *indexPathsToInsert = [self indexPathsForSection:section];
[self setSection:section open:YES];
[_tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationTop];
}
- (void)lojaInfoHeader:(LojaInfoHeaderView *)lojaInfoHeader sectionDidClose:(NSInteger)section {
NSArray *indexPathsToDelete = [self indexPathsForSection:section];
[self setSection:section open:NO];
[_tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
}
How can I make the section header appears above the cells? How to fix it?
Update to show how things are created
These are the class methods I'm using:
+ (CGFloat)viewHeight {
return 44.0;
}
+ (LojaInfoHeaderView *)lojaInfoHeaderForSection:(NSInteger)section withTitle:(NSString *)title opened:(BOOL)isOpen andDelegate:(id<LojaInfoHeaderDelegate>)delegate {
LojaInfoHeaderView *newHeader = [[[LojaInfoHeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
newHeader.section = section;
[newHeader setTitle:title];
newHeader.delegate = delegate;
[newHeader setOpen:isOpen animated:NO];
return newHeader;
}

I found the problem. I was setting the backgroundColor using alpha (yeah, I can't believe I miss this).
Wrong code in initWithFrame:
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];
Correct code:
self.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.0];

Try to change your whole table style to be grouped instead of plain. Or change your section view to be opaque. Whatever is the design requirement.

Related

UITableView: custom header title view doesn't show

I want to display a table with custom header titles.
The table view is attached to a controller class that implements the tableview delegate and data source protocols but is not a subclass of UIViewController because the table is a subview to be displayed above another tableview.
some snippets of my code:
The tableview is created programmatically:
_myListView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStyleGrouped];
[_myListView setDataSource:self.myListController];
[_myListView setDelegate:self.myListController];
[_myListView setBackgroundColor:darkBackgroundColor];
where myListController is a strong property in the class.
For the number of rows in sections:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
…
return count;
}
The number of sections:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [someDelegate sectionCount];
}
For the custom Header View:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, SectionHeaderHeight)];
UILabel* sectionHeaderTitle = [[UILabel alloc] initWithFrame:CGRectMake(20, 3, 300, 24)];
[headerView setBackgroundColor:[UIColor clearColor]];
sectionHeaderTitle.text = [self myTitleForHeaderInSection:section];
sectionHeaderTitle.textColor = [UIColor whiteColor];
sectionHeaderTitle.textAlignment = UITextAlignmentLeft;
[headerView addSubview:sectionHeaderTitle];
return headerView;
}
For the custom headerViewHeight (as required since iOS5):
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if ( [self tableView:tableView numberOfRowsInSection:section] > 0) {
return SectionHeaderHeight;
} else {
return 0;
}
}
Sadly, the tableview does not display any section headers just as if I would return nil.
However, I have checked with a breakpoint, that the code actually returns an UIView.
Everything else works fine.
What am I missing? PLease, don't hesitate to make me feel ashamed of my self.
I don't really understand why you want to use a custom view, and not the "standard" one ? You may have your reasons, but I don't see anything in your code telling me why :)
I would personally just use this:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) return #"First section header title";
if (section == 1) return #"Second section header title";
else return nil;
}
Tell me if that's not what you're looking for !
I seem to have found a solution:
I have created a lazy loading strong property for each header view I want to display. (luckily there are only three)
Now the views are shown.
It seems that the header views got deallocated without the strong references before the table was rendered.
Could it be that there is a connection to the class implementing the table view delegate and data source protocols is not a UIViewController?
Text Color you change it to Black color and check once.
sectionHeaderTitle.textColor = [UIColor blackColor];
you try this code this work on my side :-)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 24)];
UIImage *myImage = [UIImage imageNamed:#"SectionBackGround.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
imageView.frame = CGRectMake(0,0,320,24);
UIImage *imageIcon = [UIImage imageNamed:#"SectionBackGround.png"];
UIImageView *iconView = [[UIImageView alloc] initWithImage:myImage];
iconView.frame = CGRectMake(0,0,320,24);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 24)];
label.text = [tableView.dataSource tableView:tableView titleForHeaderInSection:section];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:14];
[view addSubview:imageView];
[view addSubview:iconView];
[view addSubview:label];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 24;
}

Customize header section for UITableViewController

I'll need to customize the header section of a UITableViewController where for each sections a different header text is returned (getting data from datasource as well). This is accomplished using the following:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSArray *temp = [listOfMBeans allKeys];
DLog(#"MBean details: %#", temp);
NSString *title = [temp objectAtIndex:section];
DLog(#"Header Title: %#", title);
return title;
};
This works well and I can see the expected output. However I need to change also the font size of text and after looking at similar questions I've implemented the following:
- (UIView *) tableview:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
DLog(#"Custom Header Section Title being set");
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
label.text = [tableView.dataSource tableView:tableView titleForHeaderInSection:section];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:14];
[headerView addSubview:label];
return headerView;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44.0;
}
However it seems that the code is never called. My understanding was that UITableViewController is setting by default itself as delegate but it seems I'm wrong.
The UITableViewController is created in this way (as part of hierarchical data):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ProjectDetails *detailViewController = [[ProjectDetails alloc] initWithStyle:UITableViewStyleGrouped];
detailViewController.project = [listOfMetrics objectAtIndex:indexPath.row];
// Push the detail view controller.
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
}
What changes, I should make to make this working?
Thanks.
This question is an older one but I wanted to share my code. I'm using a usual table cell view for my section headers. I have designed it with interface builder and implemented the following delegate method.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: #"Header"];
cell.textLabel.text = #"test";
return cell;
}
You can set explicitly the delegate:
detailViewController.tableView.delegate = detailViewController;
Or you can do it in the controller initial function.
EDIT: your init method should conform to the canonical init. Furthermore, it seems to me that you have not created your UITableView. Try and use this code:
- (id)initWithStyle:(UITableViewStyle)style {
if ((self = [super initWithStyle:style])) {
self.tableView = [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth UIViewAutoresizingFlexibleHeight;
self.tableView.delegate = self;
}
return self;
}
Of course, you could also do all of this in a nib file...
Here is how you get the barebones section view up using the UITableViewDelegate methods:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40.0)];
header.backgroundColor = [UIColor grayColor];
UILabel *textLabel = [[UILabel alloc] initWithFrame:header.frame];
textLabel.text = #"Your Section Title";
textLabel.backgroundColor = [UIColor grayColor];
textLabel.textColor = [UIColor whiteColor];
[header addSubview:textLabel];
return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 40.0;
}
You could try this: In your ProjectDetails.h declare a UIView *tableHeader and also an accessor method - (UIView *)tableHeader;. Then in the implementation file:
- (UIView *)tableHeader {
if (tableHeader)
return tableHeader;
tableHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
// addlabel
return tableHeader;
}
In viewDidLoad, call: self.tableView.tableHeaderView = [self tableHeader];
I don't believe you'll need to use the heightForHeaderInSection method.

TableView Row unable to Select

I defined my own controller with no nib file like this:
#interface EngineViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
EngineViewProperties* viewProp;
UIImageView *imgView; // image view of selected engine
NSUInteger selectedIndex;
UITableView *menu;
}
#property (nonatomic,retain) EngineViewProperties* viewProp;
- (EngineViewController *) initWithEngineViewProperties: (EngineViewProperties *) _viewProp;
- (void) dropdownMenu: (id) sender;
I created my view in loadView,with three subviews. The subview arrowBtn is helped to popup a list of search engines.
- (void)loadView {
// ...
UIButton *arrowBtn = [[UIButton alloc] initWithFrame:rect];
[arrowBtn setImage:viewProp.arrowImg forState:UIControlStateNormal];
[arrowBtn addTarget:self action:#selector(dropdownMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imgView];
[self.view addSubview:label];
[self.view addSubview:arrowBtn];
// ...
}
I create a table listing search engines in the selector dropdownMenu:
- (void) dropdownMenu: (id) sender {
UIButton *arrowBtn = (UIButton *)sender;
// ...
menu = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
menu.delegate = self;
menu.dataSource = self;
menu.backgroundColor = [UIColor blackColor];
menu.allowsSelection = YES;
[self.view addSubview:menu];
[self.view bringSubviewToFront:menu];
[menu release];
}
And I implemented
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
as usual.
But the result is that the menu popup happily,but I can do nothing with the cells.I clicked the cells,but no response.Those methods like "didSelectRowAtIndexPath" can not be called.
Sorry to paste up so much codes one time.But I really need help.I don't know what is the problem.Please forgive me for my poor English and low development skill in Iphone.And thanks a lot if you give me a little suggestions.
//Added-------------------------
"numberOfRowsInSection" is simple:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [viewProp.txtArray count];
}
and another method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MenuItems = #"MenuItems";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MenuItems];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: MenuItems] autorelease];
}
NSUInteger row = [indexPath row];
cell.imageView.image = [viewProp.imgArray objectAtIndex:row];
cell.textLabel.text = [viewProp.txtArray objectAtIndex:row];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont systemFontOfSize:12.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone; // Blue style tried,helpless too
if (row == selectedIndex) {
cell.selected = YES;
}
cell.userInteractionEnabled = YES;
return cell;
}
// Added
Strangely,when the menu firstly poped up,the default selected cell was highlighted correctly,but very quickly the highlighting disappeard.
Check if you have implemented this
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
The didSelectRowAtIndexPath will not called if this is present. One way to workaround this is set [self.view addGestureRecognizer:tap]; towards your targeted view only such as [self.svContent addGestureRecognizer:tap];.
Alternatively, check which view is touched.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ((touch.view == YourTable))
{
return NO;
}
return YES;
}
Try giving cell.selectionStyle = UITableViewCellSelectionStyleBlue in your table View data source. Also check if the userInteraction is enabled for the table view and the cells.
Are you showing any data in the table have you implemented
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
in you viewController??
Seems that you are setting the delgate property correctly, also you added the protocols to the same ViewController. So the problem can be either there is no data in the tableView for selection, or there is some View on top of tableView which is blocking you interaction with the tableView.
Use
cell.selectionStyle = UITableViewCellSelectionStyleGray;
in your
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
for your cell.
remove
cell.userInteractionEnabled = YES;
code from your file.

UITableView No Data Screen

My UITableView get data off the internet. Sometimes it doesn't receive any (cell) data. It just shows a blank table.
How can I show a message/cell to the user that no data records have been found?
You want to return one cell reporting on the lack of data.
If you're keeping your cell data in an array that's a class property (let's say NSArray *listings), you can go:
-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
if ([self.listings count] == 0) {
return 1; // a single cell to report no data
}
return [self.listings count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.listings count] == 0) {
UITableViewCell *cell = [[[UITableViewCell alloc] init] autorelease];
cell.textLabel.text = #"No records to display";
//whatever else to configure your one cell you're going to return
return cell;
}
// go on about your business, you have listings to display
}
You can add a test in your -tableView:cellForRowAtIndexPath: implementation and display a special UITableViewCell saying "no results available" when you get no data.
Another approach, which generally looks better, is to add a custom view to the UITableView directly. Don't forget to remove it when there are results to display.
You can add a UILabel to your view
This can be created programmatically or in your xib. If your xib contains a UITableView as [self view], as is typical for a UITableViewController, then create a property for the label on your viewController
#property (nonatomic, retain) IBOutlet UILabel *noResultsLabel;
Drag a UILabel from the library into the document window as a sibling to your "Table View".
Set text properties (36pt bold font, light gray looks pretty good)
Control drag from "File's Owner" to wire the outlet to the label.
In your server callback, you can add the label to the view. Here's an example:
#pragma mark -
#pragma mark Server callbacks
- (void)serviceExecutionComplete:(NSMutableArray *)results {
[self setServerData:results];
if ([results count] == 0)
{
// no results,
CGRect viewFrame = [[self view] frame];
[[self noResultsLabel] setFrame:CGRectMake(0, (viewFrame.size.height - 100) / 2, viewFrame.size.width, 50.0)];
[[self view] addSubview:[self noResultsLabel]];
}
else
{
[[self noResultsLabel] removeFromSuperview];
[self.tableView reloadData];
}
}
You could do the same thing in tableView:numberOfRowsInSection: if that fits your design better
I was contemplating showing an emptyDataView in either header/footer, or hacking one of the row like the suggested answer from Dan.
But I think the cleanest is to create a view outside the tableView.
#property (weak, nonatomic) IBOutlet UIView *emptyDataView;
Then hide/show the view in numberOfRowsInSection: like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];
// Show empty data view if no data
_emptyDataView.hidden = ([sectionInfo numberOfObjects] == 0) ? NO : YES;
return [sectionInfo numberOfObjects];
}
This works well with Core Data NSFetchedResultsController and hide the view once there is data.
As mentioned in the below link it is easy if we create a label and set that as the background view for UITableView like below. May be it is useful for someone. http://www.appcoda.com/pull-to-refresh-uitableview-empty/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
if (data) {
self.tableView.backgroundView = nil;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
return 1;
} else {
// Display a message when the table is empty
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
messageLabel.text = #"No data is currently available. Please pull down to refresh.";
messageLabel.textColor = [UIColor blackColor];
messageLabel.numberOfLines = 0;
messageLabel.textAlignment = NSTextAlignmentCenter;
messageLabel.font = [UIFont fontWithName:#"Palatino-Italic" size:20];
[messageLabel sizeToFit];
self.tableView.backgroundView = messageLabel;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return 0;
}
Here i use code like:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
NSInteger numOfSections = 0;
if ([jsonArray count] != 0){
tableview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
numOfSections = 1;
tableview.backgroundView = nil;
}
else{
UILabel *noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableview.bounds.size.width, tableview.bounds.size.height)];
noDataLabel.text = #"No item found.";
noDataLabel.textColor = [UIColor blackColor];
noDataLabel.textAlignment = NSTextAlignmentCenter;
tableview.backgroundView = noDataLabel;
tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return numOfSections;
}
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section{
return [jsonArray count ];
}

UITableView scrolling changess image inside UITableViewCell

I am displaying some data using a UITableViewController, my table has 2 static sections with 6 static rows each. And I am subclassing UITableViewCell in order to add 3 Labels and a View, in the view I draw an arrow in only one of the cells in one of the sections.
This all goes perfectly fine. Till i scroll down... then the arrow is randomly placed in other cells, once i scroll back up the arrow has again changed cells... This also happens if i try to set a backgroundColor for only one of the cells. Once I scroll down and up the cell that originally had the color no longer has it, and another seemingly random cell has the color now.
Here is some of my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
TableViewCells *cell = (TableViewCells *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TableViewCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(TableViewCells *)cell atIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 0:
{
if (indexPath.section == cotizacionIdeal)
{
cell.arrowImage = [UIImage imageNamed:#"arrowUp.png"];
[cell.nombre setText:#"Recursos"];
[cell.cantidad setText:[NSString stringWithFormat:#"%1.2f", [cotizacionPrevia.sueldoDeRecursos doubleValue]]];
[cell.porcentaje setText:[NSString stringWithFormat:#"%1.2f%#", [cotizacion.recursosPorcentaje doubleValue], #"%"]];
}
else
{
[cell.nombre setText:#"Recursos"];
[cell.cantidad setText:[NSString stringWithFormat:#"%1.2f", [cotizacionPrevia.sueldoDeRecursos doubleValue]]];
[cell.porcentaje setText:[Calculate calcPorcentaje:cotizacionPrevia.sueldoDeRecursos totalReal:self.totalReal]];
}
}
break;
case 1:
{
if (indexPath.section == cotizacionIdeal)
{
[cell.nombre setText:#"Comision de Venta"];
[cell.cantidad setText:[Calculate calcMonto:cotizacion.comisionPorcentaje total:self.totalIdeal]];
[cell.porcentaje setText:[NSString stringWithFormat:#"%1.2f%#", [cotizacion.comisionPorcentaje doubleValue], #"%"]];
}
else
{
[cell.nombre setText:#"Comision de Venta"];
[cell.cantidad setText:self.montoRealComision];
[cell.porcentaje setText:[NSString stringWithFormat:#"%1.2f%#", [cotizacion.comisionPorcentaje doubleValue], #"%"]];
}
}
UITableViewCell class:
- (id)initWithFrame:(CGRect)frame cell:(TableViewCells *)cell
{
if (self = [super initWithFrame:frame]) {
_cell = cell;
//self.opaque = YES;
//self.backgroundColor = _cell.backgroundColor;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[_cell.arrowImage drawAtPoint:CGPointMake(0, 0)];
}
#end
#implementation TableViewCells
#synthesize nombre;
#synthesize porcentaje;
#synthesize cantidad;
#synthesize arrowImage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// Initialization code
UILabel *nombreLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.nombre = nombreLabel;
[nombreLabel release];
[self.nombre setFont:[UIFont boldSystemFontOfSize:14]];
[self.contentView addSubview:self.nombre];
UILabel *porcentajeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.porcentaje = porcentajeLabel;
[porcentajeLabel release];
[self.porcentaje setFont:[UIFont italicSystemFontOfSize:10]];
[self.contentView addSubview:self.porcentaje];
UILabel *cantidadLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.cantidad = cantidadLabel;
[self.cantidad setTextAlignment:UITextAlignmentRight];
[cantidadLabel release];
[self.cantidad setFont:[UIFont boldSystemFontOfSize:14]];
[self.contentView addSubview:self.cantidad];
cellContentView = [[TableViewCellContentView alloc] initWithFrame:CGRectZero cell:self];
cellContentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:cellContentView];
}
UPDATE:
I have also tried setting the image to a different one for everyone but one and I am still having the same issue.
- (void)configureCell:(TableViewCells *)cell atIndexPath:(NSIndexPath *)indexPath {
cell.arrowImage = [UIImage imageNamed:#"arrowDown.png"];
switch (indexPath.row) {
case 0:
{
if (indexPath.section == cotizacionIdeal)
{
cell.arrowImage = [UIImage imageNamed:#"arrowUp.png"];
[cell.nombre setText:#"Recursos"];
[cell.cantidad setText:[NSString stringWithFormat:#"%1.2f", [cotizacionPrevia.sueldoDeRecursos doubleValue]]];
[cell.porcentaje setText:[NSString stringWithFormat:#"%1.2f%#", [cotizacion.recursosPorcentaje doubleValue], #"%"]];
}
else
{
The problem is that whenever you use drawRect for a cell you MUST call setneedsdisplay. That is what fixed my problem.
The issue is that the UITableView reuses cells so that it doesn't need to make more instances than are displayed and you're not explicitly removing the arrow in your configureCell method.
If the arrow shouldn't be displayed on a cell, explicitly clear it out in the configureCell method and that should fix it.
I am not 100% on this but I think it is to do with the release of the image. When you use imageNamed, the instance is retained so it is suggested to use imageWithFilePath instead.
Hope this helps....