Table view button index cell - ios

I have one table view in that cell is custom. I am adding two button on each cell of table view. when I click on first button at same time second button from same cell is changing its image. for that I have methods as editQuantity and Cancelorder. using #sel. I am getting an issue that when i click on first button insted of changing same cell another button its changing another cells button also when I scroll table view its losses all selected button
Here Is My Code--
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
simpleTableIdentifier = #"MenuNameCell";
MenuNameCell *cell = (MenuNameCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
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];
}
// Creating Label Menu Name
_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 11, 82, 21)];
_nameLabel.backgroundColor = [UIColor clearColor];
_nameLabel.text = [_hotel._orderedMenus objectAtIndex:indexPath.row];
// Creating Label Menu Cost
_amountMenu = [[UILabel alloc] initWithFrame:CGRectMake(167, 13, 44, 21)];
_amountMenu.backgroundColor = [UIColor clearColor];
_amountMenu.text = [[_hotel._menuPrices objectAtIndex:indexPath.row] stringValue];
// Creating Text Field For Order Quantity
_textFieldQuantity = [[UITextField alloc] initWithFrame:CGRectMake(125,14,42,21)];
_textFieldQuantity.userInteractionEnabled = NO;
_textFieldQuantity.text = [[_hotel._selectedQuantity objectAtIndex:indexPath.row] stringValue];
// Creating Button For Check Order
_checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_checkButton setFrame:CGRectMake(232, 13, 25, 28)];
[_checkButton setTag:indexPath.row];
_checkButton.titleLabel.tag = indexPath.row;
[_checkButton setBackgroundImage:[UIImage imageNamed:#"edit.png"]forState:UIControlStateNormal];
[_checkButton addTarget:self action:#selector(editQuantity:) forControlEvents:UIControlEventTouchUpInside];
// Creating Button For CANCEL Order
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_cancelButton setFrame:CGRectMake(265, 13, 25, 28)];
[_cancelButton setBackgroundImage:[UIImage imageNamed:#"cancel.png"] forState:UIControlStateNormal];
[_cancelButton setTag:indexPath.row];
_cancelButton.titleLabel.tag = indexPath.row;
[_cancelButton addTarget:self action:#selector(cancelOreder:) forControlEvents:UIControlEventTouchUpInside];
// Adding All To Content View
[cell.contentView addSubview:_nameLabel];
[cell.contentView addSubview:_amountMenu];
[cell.contentView addSubview:_textFieldQuantity];
[cell.contentView addSubview:_checkButton];
[cell.contentView addSubview:_cancelButton];
//objc_setAssociatedObject(_checkButton, iindex, indexPath,OBJC_ASSOCIATION_RETAIN );
return cell;
}
-(void)editQuantity:(id)sender{
button = (UIButton *)sender;
row = button.tag;
col = button.titleLabel.tag;
NSLog(#"Check Button index is %d",row);
NSLog(#"cehck title is %d",col);
_textFieldQuantity.userInteractionEnabled = YES;
UIImage *buttonImage = [UIImage imageNamed:#"edit_over.png"];
[_checkButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
UIImage *buttonImageCancel = [UIImage imageNamed:#"check.png"];
[_cancelButton setBackgroundImage:buttonImageCancel forState:UIControlStateNormal];
_cancelButton.tag = 0;
}
-(void)cancelOreder:(id)sender{
button = (UIButton *)sender;
row = button.tag;
NSLog(#"The Row Selected iS At Cancel Order ISSSS----%d", row);
if (_cancelButton.tag == 0){
_textFieldQuantity.userInteractionEnabled = NO;
UIImage *buttonImageCancel = [UIImage imageNamed:#"check_over.png"];
[_cancelButton setBackgroundImage:buttonImageCancel forState:UIControlStateNormal];
UIImage *buttonImageCancel1 = [UIImage imageNamed:#"cancel.png"];
[_cancelButton setBackgroundImage:buttonImageCancel1 forState:UIControlStateNormal];
UIImage *buttonImage = [UIImage imageNamed:#"edit.png"];
[_checkButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
_cancelButton.tag = 1;
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"iHomeDelivery" message:#"Do You Want To Cancel the Order" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}

The problem is that the default tag value for any control is set to 0 and you have used the _cancelButton.tag = 0;. Just change the value to 10 and then _cancelButton.tag = 1; change 1 to 11.
This will solve your problem :)

As I see _checkButton, _nameLabel, _amountMenu, _textFieldQuantity & _cancelButton all are instance variable of your view controller class.
In cellForRowAtIndexPath: as you are assigning new objects to all these, they will refere to objects of last cell displayed. Means all these will point to components from last cell.
Hence changing background images for _checkButton & _cancelButton will affect for buttons in last cell.
Also in cellForRowAtIndexPath: while creating these buttons, you are setting background image for them, hence after scrolling your button images are getting changed. Remember cellForRowAtIndexPath: gets called for a row each time that row becomes visible after getting hidden while scrolling.
You need to maintain state of buttons in separate array, so that you can reset state for buttons in cellForRowAtIndexPath: after dequeuing.

Related

uibutton background image not changing objective c

I have table view with custom cell class.
Inside cell I've five uibuttons and in its custom class I've made outlets for all of them and have only one function to handle their tap events like this.
- (IBAction)starClicked:(id)sender {
UIButton *btn = (UIButton*)sender;
switch (btn.tag){
case 501:
self.starOne = [UIButton buttonWithType:UIButtonTypeCustom];
[self.starOne setBackgroundImage:[UIImage imageNamed:#"day-time-temp-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected];
[self.starOne setTitle:#"23" forState:UIControlStateNormal];
[self.starOne setNeedsLayout];
self.starTwo = [UIButton buttonWithType:UIButtonTypeCustom];
[self.starTwo setBackgroundImage:[UIImage imageNamed:#"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected];
self.starThree = [UIButton buttonWithType:UIButtonTypeCustom];
[self.starThree setBackgroundImage:[UIImage imageNamed:#"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected];
self.starFour = [UIButton buttonWithType:UIButtonTypeCustom];
[self.starFour setBackgroundImage:[UIImage imageNamed:#"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected];
self.starFive = [UIButton buttonWithType:UIButtonTypeCustom];
[self.starFive setBackgroundImage:[UIImage imageNamed:#"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected];
break;
...
}
}
by using tag property I am checking which button is tapped, and it is working fine as I have checked it using break point. and when I press first button I want to change image of first button. And on second button I want to change image of first and second button. It is like a rating control. I want to change star image with highlighted image of star.
but below code not working. I have tried setting setNeedLayout too. But image is not changing.
Edit
this is my cell for row function.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QuestionsCell *cell = [tableView dequeueReusableCellWithIdentifier:#"questCell"];
if(cell == nil){
cell = [[QuestionsCell alloc] init];
}
[cell customizeCellWithQuestions:[self.questionList objectAtIndex:indexPath.row] textSize:1 index:indexPath.row];
return cell;
}
This is my customizeCellWithQuestions function inside my QuestionCellClass.
-(void)customizeCellWithQuestions:(Question *)question textSize:(float)textSize index:(NSUInteger)index{
[self.questionTitleTv setText:[question.question capitalizedString]];
[self.questionIndexLbl setText:[NSString stringWithFormat:#"%lu",(unsigned long)index+1]];
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor colorWithRed: 213.0/255.0 green: 213.0/255.0 blue: 213.0/255.0 alpha: 0.0];
}
You need to set Image for one state individually.
Using OR operator won't work
[self.starOne setBackgroundImage:[UIImage imageNamed:#"day-time-temp-icon.png"] forState:UIControlStateNormal];

Get click of imageview(added dynamically) within a row of uitableview in ios

I have a tableview whose rows are dynamic and each row have n numbers of imageviews as it is in the screenshot attached
Now what I want is to know which imageview I have clicked.
NOTE : imageview is added dynamically to one view and that view is added to scrollview so that it can scroll horizontally.
And there are n numbers of row in a tableview.
EDIT:
I tried adding simple button as well above the image view just to try out if that clicks but its click also didn't work.
I tried the solution of Gesture as well but that also didn't work
CODE:
-(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *strrowId ;
UITableViewCell *cell = [_tblviewScroll1 dequeueReusableCellWithIdentifier:#"cellOne"];
// create and add labels to the contentView
[cell.contentView setBackgroundColor:[UIColor colorWithRed:231.0/255.0 green:231.0/255.0 blue:231.0/255.0 alpha:1.0]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// cell.contentView.userInteractionEnabled=NO;
scrollView1 = (UIScrollView*)[cell.contentView viewWithTag:3];
[scrollView1 setShowsVerticalScrollIndicator:NO];
scrollView1.delegate = self;
NSArray* subviews1 = [scrollView1 subviews];
for (UIView* subview in subviews1) {
[subview removeFromSuperview];
}
if (scrollView1.contentOffset.y > 0 || scrollView1.contentOffset.y < 0 )
scrollView1.contentOffset = CGPointMake(scrollView1.contentOffset.x, 0);
[scrollView1 setBackgroundColor:[UIColor colorWithRed:231.0/255.0 green:231.0/255.0 blue:231.0/255.0 alpha:1.0]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleBlack;
scrollView1.clipsToBounds = YES
scrollView1.scrollEnabled = YES;
for (int i = 0; i <mutSubTitle.count; i++)
{
NSString *ids = #"";
UIView *viewvertically1;
viewvertically1=[[UIView alloc]init];
viewvertically1.tag = (i+1);
[viewvertically1 setUserInteractionEnabled:YES];
[viewvertically1 setBackgroundColor:[UIColor whiteColor]];
//Displaying image
NSString *strImgUrl = #"https://img.xxxx.com/";
NSString *strimge=[mutSubImag objectAtIndex:i];
strImgUrl = [strImgUrl stringByAppendingString:strimge];
NSURL *url = strImgUrl;
UIImage *image = [UIImage imageNamed:url];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame= CGRectMake(0, 10, 170, 110);
imageView.tag = i; // tag our images for later use when we place them in serial fashion
[imageView setUserInteractionEnabled:YES];
// images with Lazy Loading
[imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:#"Placeholder.png"]];
UITapGestureRecognizer *imgTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(gestureTapEvent:)];
imgTapGesture.numberOfTouchesRequired = 1;
[imageView addGestureRecognizer:imgTapGesture];
[viewvertically1 addSubview:imageView];
[viewvertically1 addSubview:lblDesc];
[scrollView1 addSubview:viewvertically1];
//[cell bringSubviewToFront:scrollView1];
}
return cell;
}
In your cellForRowAtIndexPath method add the UITapGestureRecognizer for your Concept
// by default the imageview userInteraction is disable you need to manually enable
cell.yourimageView.userInteractionEnabled = YES;
// the following line used for assign the different tags for eachImage
cell.yourimageView.tag = indexPath.row;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(ImageTapped:)];
tap.numberOfTapsRequired = 1;
[cell.yourimageView addGestureRecognizer:tap];
finally need to check which imageView was clicked, check the flag in selector method
-(void)ImageTapped :(UITapGestureRecognizer *) gesture
{
// you can get tag in which image is selected
NSLog(#"Tag = %d", gesture.view.tag);
}
Try giving a button instead of image view added to a view. Assign the image to button's backgroundImageView. You can then give actions for the buttons
Use UIButton as #Arun says or the imageview ur using currently add button on Image with clear background color and add tag to that button and use that click action.

UITableViewCell not showing first MPMoviePlayerController video on the cell in iOS 7?

I am trying to add video on UITableViewCell the video is adding perfectly but the problem is that when I add second video the first cell on UITableViewCell is got black and second cell showing video.
I want all my cell showing video first frame(video picture)
But it is showing only last one(Last cell)
Then I add UIButton to play every cell video it is working perfectly.
My Problem is that I want all my cell showing video first frame(video picture) on every UITableViewCell.
But problem is if only one cell add then it is showing video first picture perfectly. Then I click button and its started video perfectly but when I add second video the first one got black and second one work perfectly.
Here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"listData"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil] autorelease];
cell.selectedBackgroundView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#".png"] ];
cell.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#".png"] ];
[cell setBackgroundColor:[UIColor clearColor]];
UILabel * lbl =[[UILabel alloc]initWithFrame:CGRectMake(330, 80, 135, 41)];
lbl.backgroundColor = [UIColor clearColor];
lbl.text = #"Play Video Here";
[cell.contentView addSubview:lbl];
NSInteger x = [[NSUserDefaults standardUserDefaults] integerForKey:#"cellRowNumber"];
NSLog(#"x is %d",x);
if (x<1) {
x = 0;
}
NSURL* url = [UIAppDelegate.videoUrlsArray objectAtIndex:indexPath.row];
NSLog(#"selected tableview row is %d",indexPath.row);
NSInteger p = indexPath.row ;
NSLog(#"P is %d",p);
secView2 =[[UIView alloc]initWithFrame:CGRectMake(84,5,600,170)];
secView2.tag = indexPath.row;
secView2.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:secView2];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = CGRectMake(0,0,600,170);
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[moviePlayer prepareToPlay];
moviePlayer.shouldAutoplay = NO;
[secView2 addSubview:moviePlayer.view];
playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
playBtn.tag = indexPath.row;
playBtn.frame = CGRectMake(0,0,600,170);
[playBtn setBackgroundColor:[UIColor clearColor]];
playBtn.tag = indexPath.row;
[playBtn addTarget:self action:#selector(didButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
[secView2 addSubview:playBtn];
}
// moviePlayer.contentURL = [UIAppDelegate.videoUrlsArray objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//[self.moviePlayer pause];
return cell;
}
else {
// Nothing
}
//cell.textLabel.text = [UIAppDelegate.youTubeUrlsArray objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}
-(void)didButtonTouchUpInside:(id)sender{
UIButton *btn = (UIButton *) sender;
CGRect buttonFrameInTableView = [btn convertRect:btn.bounds toView:table];
NSIndexPath *indexPath = [table indexPathForRowAtPoint:buttonFrameInTableView.origin];
NSLog(#"%d",indexPath.row);
secView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 960)];
secView.backgroundColor = [UIColor redColor];
[self.view addSubview:secView];
NSURL* url = [UIAppDelegate.videoUrlsArray objectAtIndex:indexPath.row];
// Now set up the movie player controller and play the movie.
player = [[MPMoviePlayerController alloc] initWithContentURL: url];
[[player view] setFrame: CGRectMake(0, 50, 768, 910)]; // frame must match parent view
[secView addSubview: [player view]];
[player play];
//btn_hideSecview = [UIButton buttonWithType:UIButtonTypeCustom];
btn_hideSecview =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 45)];
btn_hideSecview.backgroundColor = [UIColor greenColor];
// btn_hideSecview.frame = CGRectMake(600, 0, 70, 45);
[btn_hideSecview setBackgroundColor:[UIColor whiteColor]];
[btn_hideSecview addTarget:self action:#selector(method_Hide_Secview) forControlEvents:UIControlEventTouchUpInside];
[secView addSubview:btn_hideSecview];
}
Any idea or suggestions would be highly welcome.
As I understand you have created "secView2" and "moviePlayer" as local properties, that means you use only one instance of these classes. For each invoke of table delegate method cellForRowAtIndexPath - create new object of MoviePlayer and UIView. If you need access outside of that delegate, prepare some DataSource NSMutableArray which will store that instances.
MPMoviePlayerController * newPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
and
UIView *secView2 =[[UIView alloc]initWithFrame:CGRectMake(84,5,600,170)];

Adding a delete button to UiTableViewCell

Since I am using a slide-out menu controller in my app - the swipe to delete on a UITablewViewCell no longer works as the pan gesture is used to open / close the side menu.
So, I was thinking about adding a delete button to show up on each cell all the time - so user can just tap delete to remove the cell.
I added this code to UItableView cellforRowAtIndexPath method:
/* Remove Button */
UIButton *removeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
removeButton.frame = CGRectMake(200.0f, 5.0f, 75.0f, 30.0f);
[removeButton setTitle:#"Remove" forState:UIControlStateNormal];
removeButton.tintColor = [UIColor colorWithRed:0.667 green:0.667 blue:0.667 alpha:1]; /*#aaaaaa*/
removeButton.titleLabel.font = [UIFont systemFontOfSize:15];
[cell addSubview:removeButton];
[removeButton addTarget:self
action:#selector(removeItem:)
forControlEvents:UIControlEventTouchUpInside];
This adds the button and in the remove method I am not sure how to go about actually removing the correct cell.
Can anyone point me in the right direction here?
Thanks!
Basically you need index for the cell which has to be deleted when delete is pressed.
you can set the tag property and when button is pressed you can check the tag propery of the button which is sending event.
see below code,
UIButton *removeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
removeButton.tag = indexPath.row;
removeButton.frame = CGRectMake(200.0f, 5.0f, 75.0f, 30.0f);
[removeButton setTitle:#"Remove" forState:UIControlStateNormal];
removeButton.tintColor = [UIColor colorWithRed:0.667 green:0.667 blue:0.667 alpha:1]; /*#aaaaaa*/
removeButton.titleLabel.font = [UIFont systemFontOfSize:15];
[cell addSubview:removeButton];
[removeButton addTarget:self
action:#selector(removeItem:)
forControlEvents:UIControlEventTouchUpInside];
-(void) removeItem:(id) sender
{
UIButton *button = (UIButton*)sender;
int index = button.tag;
}
Try this,
- (IBAction)removeItem:(id)sender {
UIButton *button = (UIButton *)sender;
CGPoint pointInTable = [button convertPoint:button.bounds.origin toView:_tableView];
NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:pointInTable];
//Remove the cell at indexPath
}
//1. add tag to the button, for identifing later
removeButton.tag = indexPath.row;
//2. Get the cell
UITableViewCell *cellToBeDeleted = [tableView cellForRowAtIndexPath:sender.tag];

How to set the position of ImageView after getting x and y postion on finger touch in iphone

I am making an ipad app in which I have tableView with custom it works fine but I want that when user clicks on add button in custom cell then it should get the position x and y of that button and then set the imageView to the center of that button.
I have searced code it gets points but how to add make this for cell.addButton as cell is custom.
[cell.imageButton addTarget:self action:#selector(imageButtonActionOne:) forControlEvents:UIControlEventTouchUpInside];
[cell.addButton addTarget:self action:#selector(imageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
Here is the code for touch
UITapGestureRecognizer *rec = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapRecognized:)];
[cell.addButton addGestureRecognizer:rec];
[rec release];
But in this way it does not call the method which is on cell.addButton imageButtonAction.
As I understand from you , you need to set an image in a UIButton upon tap.
If you added the UITapGestureRecognizer you removed the default tap recognition and now only this would work:
UITapGestureRecognizer *rec = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapRecognized:)];
[cell.addButton addGestureRecognizer:rec];
[rec release];
You should remove the above code and only set this:
[cell.addButton addTarget:self action:#selector(imageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
where the imageButtonAction: is :
- (void )imageButtonAction:(UIButton *) b
{
[b setImage:[UIImage imageNamed:#"img.png"] forState:UIControlStateNormal];
}
If you want to add an image next to the button let's say in the left of the button then the function should look like this:
- (void )imageButtonAction:(UIButton *) b
{
UITableViewCell *cell = (UITableViewCell*)[b superview];
NSInteger imgWidth = 50;
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(b.frame.origin.x - imgWidth,b.frame.origin.y,imgWidth,b.frame.size.height)];
img.backgroundColor = [UIColor redColor];
[cell addSubview:img];
[img release];
}
UIButton *btn = (UIButton *)sender;
UIImageView *backimage = [[UIImageView alloc] initWithFrame:CGRectMake(10,0,312,105)];
//If you want to do this set interaction enabled.
backimage.userInteractionEnabled = YES;
backimage.image=[UIImage imageNamed:#"popupj.png"];
tab1 = [UIButton buttonWithType:UIButtonTypeCustom];
[tab1 setFrame:CGRectMake(-1,2,293,58)];
[tab1 setTitle:#"Record Video" forState:UIControlStateNormal];
[tab1 addTarget:self action:#selector(tab1Action) forControlEvents:UIControlEventTouchUpInside];
[tab1 setImage:[UIImage imageNamed:#"popuptab1j.png"] forState:UIControlStateNormal];
[backimage addSubview:tab1];
now i am adding button to imageView but it does not get clicked
For UIButton you can use directly button function
-(IBAction) imageButtonAction:(id) sender
{
UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
UIButton *btn = (UIButton *)sender;
//[btn setimage:[UIImage imagenamed:dimagename];
UIImageview *backimage = [[UIImageView alloc] initWithFrame:btn.frame];
[cell addSubview:backimage];
}

Resources