iOS- Table row/cell behaviour when it has a details disclosure button? - ios

In my tableview I have a set number of rows and all have a detail disclosure button, clicking on detail disclosure button takes the user to a new view displaying info in a text view. I am not able to conclude on how the row should behave when user taps it because the Apple guidelines for table view and for detail disclosure button is confusing.
Please can anyone explain the below 2 scenarios for me. Thanks in advance.
Is it correct that the new view slides in only when the user taps the detail disclosure button and nothing happens when user taps elsewhere in the row.
What should be the behaviour if the user taps on the detail disclosure button with regard to highlighting?
What should be the behaviour of the table row if user taps elsewhere in the row ?
Apple guidelines says "When a detail disclosure button appears in a table row, tapping elsewhere in the row does not activate the detail disclosure button; instead, it selects the row item or results in app-defined behavior."
and Apple table view guidelines says "A table row highlights briefly when the user taps a selectable item. If a row selection results in navigation to a new screen, the selected row highlights briefly as the new screen slides into place. When the user navigates back to the previous screen, the originally selected row again highlights briefly to remind the user of their earlier selection (it does not remain highlighted)."

When you tap on the row this delegate method is invoked:
– tableView:didSelectRowAtIndexPath:
When you tap on detail disclosure button the following delegate method is invoked:
– tableView:accessoryButtonTappedForRowWithIndexPath:
tableView:accessoryButtonTappedForRowWithIndexPath:
Tells the delegate that the user tapped the accessory (disclosure)
view associated with a given row.
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
Parameters
tableView
The table-view object informing the delegate of this event. indexPath
An index path locating the row in tableView.
Discussion
The delegate usually responds to the tap on the disclosure button (the
accessory view) by displaying a new view related to the selected row.
This method is not called when an accessory view is set for the row at
indexPath. Availability
Available in iOS 2.0 and later.
Declared In UITableView.h
tableView:didSelectRowAtIndexPath:
Tells the delegate that the specified row is now selected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath Parameters
tableView
A table-view object informing the delegate about the new row selection. indexPath
An index path locating the new selected row in tableView.
Discussion
The delegate handles selections in this method. One of the things it
can do is exclusively assign the check-mark image
(UITableViewCellAccessoryCheckmark) to one row in a section
(radio-list style). This method isn’t called when the editing property
of the table is set to YES (that is, the table view is in editing
mode). See "“Managing Selections”" in Table View Programming Guide
for iOS for further information (and code examples) related to this
method. Availability
Available in iOS 2.0 and later.
See Also
– tableView:willSelectRowAtIndexPath:
– tableView:didDeselectRowAtIndexPath:
Declared In UITableView.h
Reference : UITableViewDelegate

You can do whatever you want with this discloure button. 1)New views can slide event if will tap on row. 2) nothing 3) you can dot whatever you want: show new UIViewController, UIAlertView etc. It depends on your imagination. There are no restrictions for this.

Related

What does clearsSelectionOnViewWillAppear do?

clearsSelectionOnViewWillAppear is a boolean property of table and collection views, and it's set to true by default. According to the Apple Reference:
A Boolean value indicating if the controller clears the selection when the table appears.
What does that mean?
Let's say that, as is usual, you tap a cell and this presents a new view controller. Okay, but how does it do that? Your tap selects the cell. That is a visible change in the cell - the cell is highlighted.
Later, you dismiss that view controller and return to your table / collection view.
The question is: should the selection (caused by your earlier tap) still be showing as a selection? Should the cell still be visibly highlighted? The default is: no. We clear the selection before you visibly return to the table / collection view.
(You could do this yourself in your viewWillAppear: implementation, but the table / collection view controller is willing to do it for you.)

Modify or delete table view cell in master-detail ipad app

I am developing a simple master-detail ipad app. Using xcode template for master-detail app when "Edit" navigation item is pressed in table view cell red circle appears which allows to delete selected cell.
In my app I would like to have the following: when edit button is pressed each cell can be deleted or modified (by performing segue to detail view). In other words with the red circle I would like to have another "icon" to modify the contents of that cell. Is it possible to perform this and how can be it done?
You can do this kind of stuff in multiple ways.
First is that you assign a custom gesture like swipe on the cell using the UIGestureRecognizer with custom selector that will called each time when the cell is swiped.
You can then display the buttons that are initially hidden from User.
Look into the following post to understand it better - How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views
You could always instead of using the default Edit button, implement a swipe feature that allows the user to swipe the cell to view more options. This link provides a tutorial walkthrough on how to implement this functionality.
Also, this StackOverflow post might help as well if this is the direction you choose to take.

Button changes cell detail label

Setup: i have a view controller with a tableview inside it. I also have a button in the view controller. What I want to do is when I click the button, it should change the detail label text. What i having going now is my button action, and then my cellForRowAtIndexPath. Essentially i need to tell me cell that when my button is click to change the detail text with whatever information i want. I'm stuck with this...I can assign the button to change any label...but i can't figure out how to change the detail label with the button click. Any help would be great.
You typically set the content of a uitableviewcell (which includes textLabel.text and detailTextLabel.text) in cellForRowAtIndexPath method using a datasource. This datasource could be any model object derived by NSObject or it could be NSDictionary. When you process the button tap in button's action method, just update your datasource object for the row/section with the desired detailTextLabel text and call [tableView reloadData] to reload your tableview.

Notification when table view row is deselected during multiselection IOS

I have a table view with multiselection enabled. I want to call a webservice when the table row is selected and a different webservice when it is deselected. I have noticed that on table view selection the didSelectRowAtindexPath is called but its not called on deselection. Is there any way to trigger an event when a row in table view is deselected.
See the UITableViewDelegate methods tableView:didDeselectRowAtIndexPath: and tableView:willDeselectRowAtIndexPath:.

Actionsheet instead of segue when clicking on uitableviewcell

Here's my ultimate goal in all of this. I have a viewcontroller with a table added to the view. I've set the cells to static, and I'm going to place the selected options in the cell. I want an actionsheet with a picker view on it. I have several arrays on the view which contain the various options. When someone clicks the cell I want it to call a method which checks which cell was click, passes the picker view the correct array of options to display and shows the action sheet.
I've manually added a table to the view using the storyboard, but when I ctrl drag from a cell it only gives me the option to add a segue. How do I set it so the cell click just goes to a method I create?
See UITableViewDelegate
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- tableView:willSelectRowAtIndexPath and - tableView:didSelectRowAtIndexPath: should work. Did you try them? Your viewController needs to adopt UITableViewDelegate.

Resources