How can I pass arguments with UIActionSheet? - iphone

I have an Action Sheet popping up and I want to pass a certain argument to a button processing method.
For example:
I have a table and I want to pass to a button processing method row number that was selected in a table.
How can I achieve this?

You would have to set this in your delegate ahead of time. You can then use this value when your delegate receives the button press notification.

If it is an integer argument, put it as the tag property of the action sheet. Otherwise, you can subclass the action sheet and put variables there, or use associative references.

if you want to pass an integer, use UIActionSheet.tag.
if you want to pass a NSString, use UIActionSheet.accessibilityValue.
these are simple and easy. no need to create an instance variable.

Related

How do I add specific content from a collection view to another one?

I have three elements in my UICollectionViewCell:
Two labels with name and price, and a quantity button.
I would like to add the name and the quantity with "didSelectItemAtIndexPath" to a specific collection view in the previous view controller and the price in another view controller. I may achieve this by using a segue to pass data to any view controller of my choice.
Also, at the same time, I want to keep track of the selections I make adding them to a table view below the collection view.
My guess is to create empty arrays for each item.. one for name, price and quantity.
I may be wrong.. and I tried to append my current selection and I know I am missing something.
To pass information to a previous viewController use a delegate protocol. Suppose a is your first viewController, and b is your second viewController.
You can create a delegate protocol in b (here you specify a func you want to execute inside of a)
Set a as the delegate for b
write a function yourDelegateFunction in a , which your delegate protocol will call to update the viewController with your first collection.
in didSelectItemAtIndexPath call delegate.yourDelegateFunction
Here's a video with an easy guide for how this works:
https://www.youtube.com/watch?v=3BcBu30thIA
If you provide a sample of your code, and highlight where you experienced issues, I can provide a more precise solution.

Storing a variable in swift after passing it

I have a variable that is passed between two tableview controllers.The cells in the first tableview have a detail label that is updated by this variable that is passed from the second one. once the string is passed i want it to save and bump out the old string.I would like the variable to stay saved until the app is uninstalled. any idea on how i would do this ? passing the data with protocol. I appreciate any help!

Single Click Binding to NSTableView

I am looking for some pointers on how to implement binding for a single click (similar to what NSTableView already has for Double Click on a row). Initially I thought, it is much simpler to leverage selectionIndexes property and make use of that. However when the table view gets loaded the value of this property corresponds to the zeroth index(first row) and it makes to think that the first row is always selected. Please note that I do not want to use the option of setting delegate/datasource for the tableview and use the available methods there.

Beginner and Blocks

Simple question.
I have a tableViewController that will display a list of search results.
I want to create a block based callback (I think that's what you would call it)
I would present the viewController
[searchResultController showSearchResults //BlockCode here {
//did select this item...
}];
but use a block so that I can detect the selection made from the tableview instead of using a delegate method.
Problem is I have no idea how to implement this. Is there a good tutorial or a simple example on how to do this?
Your search results controller needs to have a block property. This block should be defined with no return type, and should take a parameter of whatever object you are going to use to represent the selected item.
Before presenting your search results controller, set the block property to whatever you wish to do for your callback.
Within the search results controller, when a row is selected, execute the block, passing in the selected object. Either this method, or the block itself, should also dismiss your controller.

iPhone - how to pass an object to a button action

I have to pass an object to an button's action... something like
[myButton addTarget:self action:#selector(sendIt:MY_OBJECT) forControlEvents:UIControlEventTouchDown];
I cannot set a variable and use that on the method because I am on a static class.
How do I do that?
You cannot, the signature of an button's action is always*) -(IBAction)methodToCall:(id)sender where sender is your button, or whatever is calling the action.
I cannot set a variable and use that on the method because I am on a static class.
I am not sure what you mean with this.
*) There are a couple of other signatures new on the iPhone compared to the Mac, but none of those allow passing objects either.
The UIButton cannot pass object to event selector. You can use the property tag example:
myButton.tag = SOMEBUTTON_ID;
Also you can cast pointer to you object to NSInteger and assign it to tag property, but this technique does not solve problem of the lifetime of the object and in the future, such code may stop working.
I discovered a way to do that.
You create a class of UIButton and inside the class you declare a public variable that corresponds to the type of object you want to pass.
When you create the button you use that class and store the object inside its property.
then when the button is clicked you retrieve the ID, retrieve the button and the object stored inside it.
Now you have the object...