Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:02:31+00:00 2026-06-07T00:02:31+00:00

I have a dynamic tableview which has a prototype cell with a button that,

  • 0

I have a dynamic tableview which has a prototype cell with a button that, when pressed, plays a song.

I’d like for the background image on the button to change to a “stop” icon when the user presses the button to play the song, and for it to change to a “play” icon when the user presses it once again to stop the song.

To accomplish this I’ve been trying to use:
[self.beatPlayButton setBackgroundImage:[UIImageimageNamed:@"play.png"]forState:UIControlStateNormal];

My issue is that I haven’t figured out how to change only the button in the row that is being pressed since I’m using prototype cells. I’ve been hoping to find a method like didSelectObjectAtRow:atIndexPath: because didSelectRowAtIndexPath: will fire when the row is pressed, but not a button on it (unless I’m mistaken). Maybe I should be using a tag? I’m not sure. Any pointers would be greatly appreciated.

EDIT:
My code is outside of didSelectRowAtIndexPath.

Here is sample code –

- (IBAction)playStopBeat:(UIButton*)sender event:(id)event {
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
    if([self.audioPlayer isPlaying])
    {
        [self.beatPlayButton setBackgroundImage:[UIImage imageNamed:@"play.png"]forState:UIControlStateNormal];
        [self.audioPlayer stop];
        self.isPlaying = NO;
        self.audioPlayer = nil;
    }
    else {

        if (indexPath.row == 0) {
            [self.beatPlayButton setImage:[UIImage imageNamed:@"stop.png"] forState: UIControlStateNormal];
        }
        else if (indexPath.row == 1){
            [self.beatPlayButton setBackgroundImage:[UIImage imageNamed:@"stop.png"]forState:UIControlStateNormal];
        }
        else if (indexPath.row == 2){
...
//code to play song
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:02:33+00:00Added an answer on June 7, 2026 at 12:02 am

    Use tags, like you suggested. In your cellForRowAtIndexPath method give each cell a tag:

    cell.tag = indexPath.row;
    

    also set each target on the cells:

    [cell.playButton addTarget:self action:@selector(play:)forControlEvents:UIControlEventTouchUpInside];
    

    Then in your play method, use your tag for your array or w/e:

    - (IBAction)play:sender
    {
         UITableViewCell *cell = (UITableViewCell *)sender;
         NSLog(@"tag = %d", cell.tag);
    
         if(tag == 0)
         {
              //you could also use a switch statement 
         } else if(tag == 1) {
    
         }
    }
    

    ::EDIT:: (answer to comment)

    To disable the other buttons, in your play method:

    - (IBAction)play:sender
    {
         .........
         ....other code....
    
         UITableViewCell *cell = (UITableViewCell *)sender;
    
         for(int i = 0; i < [dataArray count]; i++)
         {
            UITableViewCell *tempCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
    
            if(tempCell.tag != cell.tag)
            {
    
                [cell.playButton setEnabled:NO];
            }
         }
    }
    

    In doing this though, after the song is done playing you must set them all back to enabled. This would be done in the MediaPlayers delegate method: didFinishPlaying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some dynamic buttons that look like this: <input type=button name=button id=button value=Click
I have a tableview that has a large number of fairly tall dynamic cells.
I have a table in which I want a dynamic image to load in
I've a UITableView which when a cell has the same content that other, this
I'm developping an android application. For that I need to have a dynamic tableView.
I have dynamic elements that I would like to flow downward and fill over
I have a tableview where each cell is populated with dynamic data from an
Using storyboard, I have a table view controller containing multiple dynamic prototype cells. One
I have dynamic listview on my android client app that receive data from remote
I have dynamic array filled with bytes, which are read from .raw file with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.