Yes, I know all of that.

Here's why I asked the question in the subject: A UIView cannot, by itself, 
perform a segue (at least, I don't know how). A UIViewController can do that.

Which is why I was asking how a UIButton does it (when you wire it up in IB). 
Then in my -stuffToDo:, I could perform the segue. But I didn't like the idea 
of adding a viewController property to my cells, because it seemed 
heavy-handed. Really, I just wanted to pass along some arbitrary data with the 
action message.

In the end, I used an associated object.


On Jun 25, 2014, at 16:53 , Alex Zavatone <z...@mac.com> wrote:

> A UIButton "can" perform a segue without any code, but this will make life 
> suck for you and confusion will be your best friend for a long time.
> 
> A UIButton should be declared as an "IBOutlet" property.  This essentially 
> means nothing, but tells you, the developer, that this property is an 
> Interface Builder Outlet.
> 
> Likewise, within the View Controller class that the button is defined within, 
> there should be a method that the UIButton can call upon a certain event.  
> You probably want this event to be on the releasing of a finger on the 
> button.  Thankfully, since Xcode knows that you want to wire up an "action" 
> (your method) to be performed on an IBOutlet that is a UIButton, it will 
> expect that you will want to do it on the Touch Up Inside event that happens 
> inside the button.  You can actually have a button respond to a Touch Up 
> Outside, but I'm betting that's not what you want.
> 
> So, you'll need to define a method within your class that is an IBAction 
> (also meaningless in code) so Xcode knows to wire a method that is an 
> IBAction to an IBOutlet UIButton.  
> 
> This is how you do it in Xcode.
> In your class's header file, in the @interface section, you'll need an 
> IBOutlet property and an IBAction method.  Like so:
> 
> @property (nonatomic, weak) IBOutlet UIButton *thatButtonOfMine; 
> // This is the reference to the button.  You'll have to connect it to your 
> button's referencing outlet in the storyboard
> 
> - (IBAction)stuffToDo:(id)sender; 
> // This is the method that can be called upon a button event.
> 
> So, you'll wire up the button by connecting the button in the storyboard 
> (right click, son) to the little circle next to the IBOutlet property in your 
> header file. (Or the other way around.)
> 
> But then you'll need to tell the stuffToDo method that it needs to be 
> issued/called when the "touch up inside" condition happens on the button, so 
> you can drag from your header file onto the button and Xcode will do it 
> magically, or you can right click on the button, find Touch Up Inside and 
> drag it onto the little circle next to the IBAction text in your header.
> 
> You may need to display the Assistant Editor to do this.
> 
> And finally, you'll actually have to add the method in your controllers .m 
> file.  Just add it in the same way, sort of like so:
> 
> - (IBAction)stuffToDo:(id)sender
> {
>    // stuff you want to do goes here
> }
> 
> Now, you probably want to issue a segue, that's my guess.
> 
> So, I'm sure you named all the segues you have from one class to another, so 
> if by some magic, your segue is named "Next Screen", then you would have your 
> view controller call that segue like so:
> 
>    [self performSegueWithIdentifier:@"Next Screen" sender:sender];
> 
> And you'd put it inside of - (IBAction)stuffToDo:(id)sender.
> 
> In this case, sender is the button itself, so if you really cared and wanted 
> to go to different screens based on a property of the button you could 
> totally do that.
> 
> That's pretty much it.
> 
> Cheers.
> - Alex Zavatone
> 
> 
> 
> 
> 
> On Jun 25, 2014, at 5:44 PM, Rick Mann wrote:
> 
>> I added a UIButton to a UICollectionViewCell in IB, and then dragged a segue 
>> from that to another scene. The problem I need to solve is for that 
>> destination view controller to know which represented object was associated 
>> with the cell in which the source UIButton was. But I can't see how to do 
>> that.
>> 
>> One approach is to trigger the segue programmatically from the Cell 
>> subclass, but you can't do that without knowing the view controller. How 
>> does the button do it?
>> 
>> I can think of a few other approaches, but they're all kinda gross. Any 
>> recommendations? I want to present a modal form sheet (iPad) when a button 
>> inside the UICollectionViewCell is tapped without doing the normal segue 
>> that happens when any other part of the cell is tapped (to allow the user to 
>> edit metadata for that item without opening the full UI for that item).
>> 
>> TIA,
>> 
>> -- 
>> Rick
>> 
>> 
>> 
>> 
>> _______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
>> 
>> This email sent to z...@mac.com
> 


-- 
Rick




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to