0

I'm trying to drag connections from some UIButtons on my Storyboard to a subclass of UIButton (called AGPiece in my header file. I have two storyboards for iPhone and iPad.

I was able to drag the iPhone ones over and create new outlets (@property (strong, nonatomic) IBOutlet AGPiece *piece1;, but now I'm coming to want to link the iPad storyboard to those same lines of code, I can't drag onto those lines, it doesn't get the highlight and let me, it only allows me to create a new one above or below that line. Obviously if I'd created the iPad ones first, it would've created those and not the phone, the issue is dragging to an existing line of code, as opposed to dragging out and creating a new one. It seems that Xcode expects a UIButton, and doesn't know that my AGPiece inherits from UIButton.

Is there a way around this? It worked fine when I was linking to UIButton instances and had UIButton written in the header file, but now I'm coming to implement the custom class, it doesn't want anything to do with it.

Luke
  • 9,512
  • 15
  • 82
  • 146
  • Are you sure you want to subclass UIButton? The class is a lot more complicated than you think and subclassing it can cause major problems. You are best creating a custom UIView subclass and adding a UIButton to it with no image. It is also discouraged by Apple. – Fogmeister Jan 31 '13 at 15:37
  • Fogmeister is right. If you are doing this, you probably need to set the 'class' of your button in interface builder to be your button subclass type. – Dave Jan 31 '13 at 15:44
  • Dave, that was correct. Wanna write an answer so I can credit you? :) – Luke Jan 31 '13 at 15:45
  • Fogmeister, I have a question: if I do as you suggest, can I still create the UIButtons in Interface Builder, and link them by dragging? Or with this approach, would I need to create them programmatically and position them in code? – Luke Jan 31 '13 at 16:17

2 Answers2

1

Try this... You'll notice a BULLET in the line numbers column of your .h/.m file next to properties and methods that have IBACTION or IBOUTLET. With interface builder in one view and your .h/.m file in the other view; you can click on that bullet and drag it to the button / property you want to link with.

Also - you need to be sure your ViewController has the correct "class" type (matches the name of your subclass).

You can also control drag from the button/view to the "controller" (orange square) in interface builder.

edit As per comments above: If you are subclassing a button you probably need to set the 'class' of your button in interface builder to be your button subclass type.

Dave
  • 7,552
  • 4
  • 22
  • 26
  • Bear in mind that the bullet is already filled, from the link to the iPhone storyboard. – Luke Jan 31 '13 at 15:40
  • Dragging to the controller doesn't offer those properties as choices, so that's a no-go too. My ViewController is a UIViewController, it's not a UIButton or a custom class – not sure what you mean by that one. I'm trying to link a UIButton to an AGPiece, written inside the .h of a class that inherits from UIViewController. – Luke Jan 31 '13 at 15:44
0

How did you create the ipad storyboard, I suggest you to use the method explained here: Converting Storyboard from iPhone to iPad (in short duplicate iphone storyboard file in finder, modify the target runtime property to ipad and restart xcode)

When you create the ipad storyboard like there it also preserves the outlet connections from iphone storyboard, quite handy saves lots of time for you.

Community
  • 1
  • 1
guenis
  • 2,520
  • 2
  • 25
  • 37
  • I didn't know about this, and will give it a go next time I make a project :) – Luke Jan 31 '13 at 15:47
  • You don't need to convert the whole storyboard all the time, right click storyboard file in xcode, and open it as source code. it will give you a html-like code which is sectioned by different viewcontrollers you used in the storyboard. Copy your specific vc's part from iphone's file to ipad's. – guenis Jan 31 '13 at 15:51