Re: How does a UIButton perform a segue?
On Jun 25, 2014, at 14:44 , Rick Mann rm...@latencyzero.com wrote: 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. Doesn’t ‘prepareForSegue:’ give you the information you need? Presumably ‘sender’ will be the button in this case ___ 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
Re: How does a UIButton perform a segue?
On Jun 25, 2014, at 15:58 , Quincey Morris quinceymor...@rivergatesoftware.com wrote: On Jun 25, 2014, at 14:44 , Rick Mann rm...@latencyzero.com wrote: 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. Doesn’t ‘prepareForSegue:’ give you the information you need? Presumably ‘sender’ will be the button in this case Sort of. The button is the sender. But there's no way to determine in which cell that button is. I ended up associating the model object that the cell knows about with the UIButton, and pulling that out in -prepareForSegue: -- 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
Re: How does a UIButton perform a segue?
On Jun 25, 2014, at 16:00 , Rick Mann rm...@latencyzero.com wrote: The button is the sender. But there's no way to determine in which cell that button is. Sure there is. Walk up the tree of superviews from the button till you find the enclosing cell. ___ 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
Re: How does a UIButton perform a segue?
On Jun 25, 2014, at 16:05 , Quincey Morris quinceymor...@rivergatesoftware.com wrote: On Jun 25, 2014, at 16:00 , Rick Mann rm...@latencyzero.com wrote: The button is the sender. But there's no way to determine in which cell that button is. Sure there is. Walk up the tree of superviews from the button till you find the enclosing cell. Well, I suppose, but that sort of forces the -prepare method to know a lot about the view hierarchy. I'd rather not do that. -- 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
Re: How does a UIButton perform a segue?
On Jun 25, 2014, at 16:06 , Rick Mann rm...@latencyzero.com wrote: Well, I suppose, but that sort of forces the -prepare method to know a lot about the view hierarchy. I'd rather not do that. Your original question was about finding the cell for the button. Therefore, it’s already implicit in your approach that the view controller doing ‘prepareForSegue:’ knows that the button is in a table view, hence in a cell, hence a subview of the cell. There’s no special-case knowledge involved there. The view controller doesn’t need to know in advance how many steps up there are from the button to the cell, if that’s what’s worrying you. You can use one of those loopy things to find the cell. ;) ___ 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
Re: How does a UIButton perform a segue?
Something like this: id cell = button; for(; cell ![cell isKindOfClass:[UITableViewCell class]]; cell = [cell superview]); When this loop exits you get either the cell or nil indicating that the button is not inside a cell. Sent from my iPhone On Jun 26, 2014, at 7:18, Quincey Morris quinceymor...@rivergatesoftware.com wrote: On Jun 25, 2014, at 16:06 , Rick Mann rm...@latencyzero.com wrote: Well, I suppose, but that sort of forces the -prepare method to know a lot about the view hierarchy. I'd rather not do that. Your original question was about finding the cell for the button. Therefore, it’s already implicit in your approach that the view controller doing ‘prepareForSegue:’ knows that the button is in a table view, hence in a cell, hence a subview of the cell. There’s no special-case knowledge involved there. The view controller doesn’t need to know in advance how many steps up there are from the button to the cell, if that’s what’s worrying you. You can use one of those loopy things to find the cell. ;) ___ 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/xcvista%40me.com This email sent to xcvi...@me.com ___ 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
Re: How does a UIButton perform a segue?
Yeah, maybe that's not an unreasonable way to do it. Thanks. On Jun 25, 2014, at 16:40 , ChanMaxthon xcvi...@me.com wrote: Something like this: id cell = button; for(; cell ![cell isKindOfClass:[UITableViewCell class]]; cell = [cell superview]); When this loop exits you get either the cell or nil indicating that the button is not inside a cell. Sent from my iPhone On Jun 26, 2014, at 7:18, Quincey Morris quinceymor...@rivergatesoftware.com wrote: On Jun 25, 2014, at 16:06 , Rick Mann rm...@latencyzero.com wrote: Well, I suppose, but that sort of forces the -prepare method to know a lot about the view hierarchy. I'd rather not do that. Your original question was about finding the cell for the button. Therefore, it’s already implicit in your approach that the view controller doing ‘prepareForSegue:’ knows that the button is in a table view, hence in a cell, hence a subview of the cell. There’s no special-case knowledge involved there. The view controller doesn’t need to know in advance how many steps up there are from the button to the cell, if that’s what’s worrying you. You can use one of those loopy things to find the cell. ;) ___ 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/xcvista%40me.com This email sent to xcvi...@me.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
Re: How does a UIButton perform a segue?
Yes. However you may want to use code that looked better. My code is a little bit obfuscated. Sent from my iPhone On Jun 26, 2014, at 7:46, Rick Mann rm...@latencyzero.com wrote: Yeah, maybe that's not an unreasonable way to do it. Thanks. On Jun 25, 2014, at 16:40 , ChanMaxthon xcvi...@me.com wrote: Something like this: id cell = button; for(; cell ![cell isKindOfClass:[UITableViewCell class]]; cell = [cell superview]); When this loop exits you get either the cell or nil indicating that the button is not inside a cell. Sent from my iPhone On Jun 26, 2014, at 7:18, Quincey Morris quinceymor...@rivergatesoftware.com wrote: On Jun 25, 2014, at 16:06 , Rick Mann rm...@latencyzero.com wrote: Well, I suppose, but that sort of forces the -prepare method to know a lot about the view hierarchy. I'd rather not do that. Your original question was about finding the cell for the button. Therefore, it’s already implicit in your approach that the view controller doing ‘prepareForSegue:’ knows that the button is in a table view, hence in a cell, hence a subview of the cell. There’s no special-case knowledge involved there. The view controller doesn’t need to know in advance how many steps up there are from the button to the cell, if that’s what’s worrying you. You can use one of those loopy things to find the cell. ;) ___ 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/xcvista%40me.com This email sent to xcvi...@me.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
Re: How does a UIButton perform a segue?
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
Re: How does a UIButton perform a segue?
On 26 Jun, 2014, at 7:58 am, Rick Mann rm...@latencyzero.com wrote: 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. If there's a UIViewController somewhere, it's in the responder chain. I would expect the UIButton, when hooked up in IB, just walks up that looking for the view controller. ___ 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
Re: How does a UIButton perform a segue?
On Jun 25, 2014, at 17:10 , Roland King r...@rols.org wrote: If there's a UIViewController somewhere, it's in the responder chain. I would expect the UIButton, when hooked up in IB, just walks up that looking for the view controller. So that brings up an unanswered question from yesterday. How can I programmatically send a message to the first responder? -- 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
Re: How does a UIButton perform a segue?
On 26 Jun, 2014, at 8:15 am, Rick Mann rm...@latencyzero.com wrote: On Jun 25, 2014, at 17:10 , Roland King r...@rols.org wrote: If there's a UIViewController somewhere, it's in the responder chain. I would expect the UIButton, when hooked up in IB, just walks up that looking for the view controller. So that brings up an unanswered question from yesterday. How can I programmatically send a message to the first responder? You can't, well you can, if your message looks like an action or can be made to look like an action you can use UIApplication sendAction:to:from:forEvent, with 'to' as nil and off it goes up the chain. So you should be able, if you wanted, to implement your own selector in the UIViewController subclass which has the signature of an action message and call it with that UIApplication method and the responder chain will find it for you. My bug requesting that the current firstResponder be made available as a property on UIApplication remains duped and open after 3 years. ___ 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
Re: How does a UIButton perform a segue?
On Jun 25, 2014, at 17:20 , Roland King r...@rols.org wrote: My bug requesting that the current firstResponder be made available as a property on UIApplication remains duped and open after 3 years. Or at least a -sendToFirstResponder... Sigh. Thanks! -- 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
Re: How does a UIButton perform a segue?
Looks like you're going to have to figure out how view controllers do it. I seem to recall Mike Ash doing a lot of recreating this iOS class blog entries like this: https://mikeash.com/pyblog/friday-qa-2013-02-22-lets-build-uitableview.html But I don't see a reconstruction of UIViewControllers. I'd expect it would have to work with a Navigation controller if you have a stack of view controllers that you want to be able to nav through. It seems like the view can get its view controller and tell it to perform the segue. Yeah, a view controller property might seem heavy handed, but it's just a reference to the VC that already holds the view. You're just making it easier to find. I'm sure you could look up the view's chain to find the VC also. On Jun 25, 2014, at 7:58 PM, Rick Mann wrote: 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?