Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 5 different answers depending on your desired logic and/or result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

NOTE: As Tony Million noted above, this does NOT prevent tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section.

Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.selectionStyle != UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 



5.To determine on-the-fly whether to highlight a cell (which according to this answerthis answer implicitly includes selection), you can implement the following UITableViewDelegate protocol method:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath 

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 5 different answers depending on your desired logic and/or result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

NOTE: As Tony Million noted above, this does NOT prevent tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section.

Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.selectionStyle != UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 



5.To determine on-the-fly whether to highlight a cell (which according to this answer implicitly includes selection), you can implement the following UITableViewDelegate protocol method:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath 

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 5 different answers depending on your desired logic and/or result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

NOTE: As Tony Million noted above, this does NOT prevent tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section.

Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.selectionStyle != UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 



5.To determine on-the-fly whether to highlight a cell (which according to this answer implicitly includes selection), you can implement the following UITableViewDelegate protocol method:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath 
added 5th option from comments
Source Link
mbm29414
  • 11.6k
  • 6
  • 59
  • 88

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 45 different answers depending on your desired logic and/or result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

***NOTE: As Tony Million noted above, this does NOT prevent the user from triggering tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section.NOTE: As Tony Million noted above, this does NOT prevent tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section.

Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath   { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (![cell selectionStyle]cell.selectionStyle ==!= UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

**In my testing, this still allows controls inside the UITableViewCell to be interactive.In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 



5.To determine on-the-fly whether to highlight a cell (which according to this answer implicitly includes selection), you can implement the following UITableViewDelegate protocol method:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath 

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 4 different answers depending on your desired result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

***NOTE: As Tony Million noted above, this does NOT prevent the user from triggering tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section. Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (![cell selectionStyle] == UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

**In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 5 different answers depending on your desired logic and/or result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

NOTE: As Tony Million noted above, this does NOT prevent tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section.

Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.selectionStyle != UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 



5.To determine on-the-fly whether to highlight a cell (which according to this answer implicitly includes selection), you can implement the following UITableViewDelegate protocol method:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath 
added 4 characters in body
Source Link
Paras Joshi
  • 20.5k
  • 11
  • 60
  • 71

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 4 different answers depending on your desired result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

***NOTE: As Tony Million noted above, this does NOT prevent the user from triggering tableView:didSelectRowAtIndexPath:tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section. Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (![cell selectionStyle] == UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

**In my testing, this still allows controls inside the UITableViewCellUITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 4 different answers depending on your desired result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

***NOTE: As Tony Million noted above, this does NOT prevent the user from triggering tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section. Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (![cell selectionStyle] == UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

**In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 

Because I've read this post recently and it has helped me, I wanted to post another answer to consolidate all of the answers (for posterity).



So, there are actually 4 different answers depending on your desired result:

1.To disable the blue highlighting without changing any other interaction of the cell:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

I use this when I have a UIButton - or some other control(s) - hosted in a UITableViewCell and I want the user to be able to interact with the controls but not the cell itself.

***NOTE: As Tony Million noted above, this does NOT prevent the user from triggering tableView:didSelectRowAtIndexPath:. I get around this by simple "if" statements, most often testing for the section and avoiding action for a particular section. Another way I thought of to test for the tapping of a cell like this is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // A case was selected, so push into the CaseDetailViewController UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (![cell selectionStyle] == UITableViewCellSelectionStyleNone) { // Handle tap code here } } 



2.To do this for an entire table, you can apply the above solution to each cell in the table, but you can also do this:

[tableView setAllowsSelection:NO]; 

**In my testing, this still allows controls inside the UITableViewCell to be interactive.


3.To make a cell "read-only", you can simply do this:

[cell setUserInteractionEnabled:NO]; 



4.To make an entire table "read-only"

[tableView setUserInteractionEnabled:NO]; 
Source Link
mbm29414
  • 11.6k
  • 6
  • 59
  • 88
Loading