Actionsheet instead of segue when clicking on uitableviewcell - ios

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.

Related

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.

Create an event (IBAction) from a cell

After all my searching, I didn't find any specific informations/questions on that one : I want to link a whole Table View Cell (like if it was a button) to an IBAction (which, in my case, will perform a segue).
The thing is that I apparently can't Ctrl-Drag the Cell to my code to creat an event (since there is no category for that in my connections inspector, in the storyboard). This last point makes me fear that it isn't possible.
I managed to create a segue, directly from the Cell, to another view but it gets triggered everytime I touch the Cell. And I need to have a condition on that segue, which is why I have a segue from my Table View (containing the said Cell) to the Target View. I then created an IBAction which calls the segue (Table View to Target View).
How do I link my Cell to that Segue?
PS: I can edit my question for the code, but we only have the IBAction in my TableViewController (declared as Class on my Table View in the storyboard) and then the Segue which was created using the Storyboard.
My Table is static (as for now, it's for testing).
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
There are many way to achieve this, if you just wanted a segue you can do this without code
if not do it like #waki
Cell To UIViewController:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Custom UITableViewCell Button selected - reload data

Alright let's say I have two ViewController, FirstViewController that contains a table and the CustomCell. I set up the action of the button in the CustomCell and it does what it is supposed to do but I want to call the [tableView reloadData] function in my FirstViewController.
What is the proper way of calling this function after the button is selected? Is there a way to set up something in FirstViewController that gets called when the Button in the other Class is selected?
You're best bet, if I understand your question correctly, is to use the Delegate Protocol in the second view, which returns a message to the first view controller.
See my answer here on how to setup a delegate:
How to declare events and delegates in Objective-C?

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

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.

UITableView in a View controller by a UIViewController and not a UITableView

I have a View with lots of things inside it including buttons, a scroll view and a tableView (ipad app). I am controller this view with a viewController subclass but I don't know how to manage my tableView. I don't know where put the methods :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
should I add them to my ViewController or should I create a new subclass of UITableViewController (and get them "for free") and set the dataSource and delegate of my tableView to that class when I create it programmatically?
I am storing the data I want to show in my appDelegate
.
You just have to set the UIViewController as the delegate and dataSource of your UITableView. That's it. You don't need to create a own subclass of UITableViewController for managing that tableView. So you can put all the subviews in the viewController's view.
Thank you so much, I got it. I was trying to create a tableView and then set it's datasource. In fact the easier way is to create a tableViewController and use it's .view property that is already linked to it and use the addSubview method to put it in the main viewController's view.
Cheers

Resources