Table view button as a button

I am trying to set up a Table View Cell element that has been grouped like a button, however I cannot find where to do this in the interface builder in Xcode 4.2 or programmatically.

I tried to associate a table view cell with IBAction, but that only allows me to create or reference an IBOutlet.

As a temporary fix, I put a rectangular button in the cell, but when I click it it does not highlight blue.

I saw this work in several applications, for example, the Clear History and Clear Cookies and Data buttons in the Safari application below:

enter image description here

+4
source share
2 answers

Imagine your IBAction looks like this:

-(IBAction)buttonPressed{ //Do my stuff } 

Then you should do this on your deletion:

  -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //check if your cell is pressed BOOL myCellIsPressed = ... if(myCellIsPressed) [self buttonPressed]; } 

To check if your cell has been pressed, you have several ways, for example, if you know the row of your button in the table:

 int myCellRow = 5; if (myCellRow == IndexPath.row) //YES! 

Or you can put the tag in your cell and then check if this is:

 #define myTag 5 

When creating a cell:

 UITableViewCell *myCell = ... myCell.tag = myTag 

And in the didSelectRowAtIndexPath file:

 UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; if (selectedCell.tag == myTag) //YES! 
+10
source

these are not buttons. The function of transparent cookies and other things is processed into the delegate method of the table view

  tableview : didselectRow 

Here you can find which section and which line is selected, and perform functions on it.

+1
source

Source: https://habr.com/ru/post/1399356/


All Articles