Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread Display Modes
Old Apr 3, 2009, 04:58 AM   #1
macrumors newbie
Join Date: Apr 2009
UITableViewCell and UIButton issue

I have a custom UITableViewCell and in there except from other elements i want to draw two buttons which once either pressed the one animates a transformation on the button and the other changes picture(actual actions dont matter that much).What happens is that except for the cell in which the button was pressed i see the effect in other cells too.
Also if i use an animation i see the transformed button drawn behind the normal one..one on top of the other
to be more precise heres a sample of my code:

- (UITableViewCell *)tableView:(UITableView *)tableView 
		 cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
	AnswerView * cell = (AnswerView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	UIButton * thumbsUp;
	if(cell == nil)
		cell = [[[AnswerView alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
		button= [[[UIButton  alloc] initWithFrame:CGRectMake(x, y, w, 
		button.tag = 2;
		[button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
		button = (UIButton *)[cell.contentView viewWithTag:2];

if(/* some logic involving indexPath.row */)
 [button setFrame: ] 
[button setFrame:

[cell.contentView addSubView:button];
return cell;
Is this a completely the wrong way to go ?
final1cut is offline   0 Reply With Quote
Old Apr 3, 2009, 05:10 AM   #2
macrumors 68030
johnnyjibbs's Avatar
Join Date: Sep 2003
Location: London, UK
Send a message via AIM to johnnyjibbs Send a message via MSN to johnnyjibbs
Since you have subclassed the cell, why don't you stick the buttons and all the cell layout into your AnswerView class? That way, you'll just be adding and removing AnswerView cell objects rather than keeping the buttons and cells seperately.

At the moment, I think you are running into problems when the cells are reused and you may also have a memory leak, which is why the buttons are building up on top of each other.
iMac 27" - iPhone 6 Plus - Apple Watch SS 42mm Milanese Loop
johnnyjibbs is offline   0 Reply With Quote
Old Apr 6, 2009, 05:11 AM   #3
Thread Starter
macrumors newbie
Join Date: Apr 2009
thnks for the reply...
i noticed a pattern in how the button is wrongly drawn in other cells and its every other 2 cells.Does this has to do with how the cells are reused?
final1cut is offline   0 Reply With Quote
Old Apr 6, 2009, 09:55 AM   #4
macrumors 68030
PhoneyDeveloper's Avatar
Join Date: Sep 2008
You need to addSubview the button inside the block of code where you create the cell and button. Your code is adding the subview every time, which isn't correct when reusing the cell.
PhoneyDeveloper is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPad: Superclass UIButton Kevvaere iOS 6 1 Feb 26, 2014 06:42 AM
Resolved: Showing Badge on UIButton RagingGoat iPhone/iPad Programming 1 Feb 18, 2014 12:12 PM
Weird Distortion of UIButton IDMah iPhone/iPad Programming 4 Dec 22, 2012 12:29 PM
iOS 5 - Issue with deleting UITableViewCell with NSFetchedResultsControlller and Cust mdhansen5 iPhone/iPad Programming 2 Jun 15, 2012 07:59 AM
Custom Delete UITableViewCell mdhansen5 iPhone/iPad Programming 1 Jun 1, 2012 10:41 AM

Forum Jump

All times are GMT -5. The time now is 09:28 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC