Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

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

Hi
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:

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, 
															   h)]autorelease];
		button.tag = 2;
		[button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
	}
	else
		button = (UIButton *)[cell.contentView viewWithTag:2];

if(/* some logic involving indexPath.row */)
 [button setFrame: ] 
else
[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
johnnyjibbs
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.
johnnyjibbs is offline   0 Reply With Quote
Old Apr 6, 2009, 05:11 AM   #3
final1cut
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
PhoneyDeveloper
macrumors 68020
 
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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Lion and graphics issues QuantumLo0p Mac OS X 10.7 Lion 0 Nov 19, 2011 11:31 AM
Animation a UIButton while animating a View - Ipad ashwinr87 iPhone/iPad Programming 3 May 25, 2011 09:56 AM
UIButton kurkah iPhone/iPad Programming 3 Apr 7, 2011 05:08 AM
UITableViewCell and a custom tappable accessory SqueegyX iPhone/iPad Programming 0 Oct 30, 2008 08:08 PM
UITableViewCell, and other element reference? Where to find? belsokar iPhone/iPad Programming 2 Jul 31, 2008 06:03 PM


All times are GMT -5. The time now is 04:47 PM.

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

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