Why XCode 4 doesn't create XIB file when using storyboard? - iphone

Why can't XCode 4 create XIB file while using storyboard: is it 2 incompatible models ? For example all tutorials about hiding keyboards seem to require XIB file:
http://www.techotopia.com/index.php/Writing_iOS_4_Code_to_Hide_the_iPhone_Keyboard_%28Xcode_4%29

Here is an update to the link in the question:
Having written the code for our method we now need to wire up our user interface so that it gets called at the appropriate time. We will perform this task in Interface Builder, so select hideKeyboardViewController.xib once more.
The equivalent of this now is to click on storyboard, and then click the hidKeyboardViewController in the storybaord window.
Select the text field in the view and display the Connections Inspector (View -> Utilities -> Connections Inspector) in the right hand panel.
The equivalent of this now is to Right click the text field.
Click on the circle to the right of the Did End on Exit event, drag the line to the File’s Owner icon and select textFieldReturn from the list of available methods.
Equivalent here is to click the circle, as mentioned, then drag the blue line to the orange box at the bottom.

Its the same, inside the storyboard you will see your views and you can do the same as you did when you were working directly with .xibs

Treat the "scenes" in the storyboard as if they were XIBs. You can layout the screen, add elements, and link them up to their respective ViewControllers. Any code you need to run should be in a ViewController, and then in the Storyboard you can indicate that a particular scene is related to that ViewController.
For your question about hiding the keyboard, you'll need to have a method in your ViewController that includes a line of code:
[myTextField resignFirstResponder];
...where myTextField is a UITextField, UITextView, or other object that requires a keyboard.

Related

How can I find the file my storyboard outlet connects to?

This may be a silly question.
I know I can easily go to my storyboard from my outlet e.g.
Is there an easy way to do the reverse? I'd like to go from my storyboard element to my swift file, specifically the line of code where the outlet is declared.
I'm not aware of any shortcut link back to the declaration of an outlet. A couple of alternatives are:
Use the Assistant Editor (it's the middle button below with the two overlapping rings) while you have a View Controller or an element within it selected in a storyboard. It will load up the accompanying class in a panel beside the storyboard view.
Select the View Controller itself out of the hierarchy, go to the Identity Inspector on the right, and tap the little gray circle icon with a white arrow in it beside the class name. That will take you to the class file in the main editor.
Those are the only two methods I know of for getting to the associated class.
Select the element and then click "Show the Assistant editor" at the top right. It will take you to the correct class, but not to the exact line it is declared on.
Select element:
Click "Show the Assistant editor":

How to swipe out of table view controller (not the cells) - iPhone

I have a tab bar app. It has 5 tabs. I have the 3rd tab connected to a navigation controller that's connected to a table view controller. Simple enough, right?
Well, I recently decided to implement left/right swipe gestures as an optional way to navigate left and right to each tab in the tab bar controlled app. The gestures work great, except I don't have a way to implement the gestures on the 3rd tab (the one with the UITableView) because there's no implementation file associated with it.
And that's my question: How can I implement the gestures on the third tab so I can navigate AWAY from it by swiping?? I can swipe into that tab, but not out of it. I'm fairly new to iOS dev, and I really appreciate any help!
(Using ARC, Storyboard, & Xcode 4.5.2)
EDIT:
Here's a screenshot of how my Table View Controller is connected to my Tab Bar Controller:
SOLUTION:
The answer marked correct is indeed correct. It explained to me how to make a subclass of my UITableViewController. But I was also wondering how to implement my TableView programmatically... so after a bit of searching, this link pretty much shows exactly how to do that: Ruchi Raval's post on mobisoftinfotech. However, I ended up just following the steps in the link, and I ended up deleting my original UITableViewController because I had created a new one through the steps in the link and connected it to my NavigationController through the Storyboard (ctrl + drag).
Hope this helps anyone that had my same quesions!
To control gestures on a VC, you'll need your own subclass. Create a new objective-c object named like MyTableViewController. Xcode lets you specify a superclass when creating the files, use UITableViewController.
Xcode provides some template code in the new files -- leave that alone to begin with. In storyboard, I think the tab you're trying to fix has a navigation (vc) whose root vc is a UITableViewController.
Select that table vc and select the Identity inspector (upper right, third tab from the left). You should see a section called custom class. The current class is probably UITableViewController. Change that to MyTableViewController, or whatever you named the new class.
Build and run. Now you control that table vc. Back in it's implementation file, you can add your gesture code in viewDidLoad:.

iOS Storyboard How to access the controls and add event handlers, and binding data to controls added on Storyboard

I used to create the UI thru code. But now I have to use storyboard. I am confused about how to add the event handlers to the controls added on the storyboard and how to bind the data dynamically to the controls added on storyboard. A sample scenario is An UIView is added on the storyboard and two UITableViews and a button are added on top of it. I want to add event handler to the button and bind data to the table views. How do I do this. If I subclass the UIView added on the storyboard will I have access to the controls(button, two table views) added on top of the view or how else I should achieve this ?. Please help !
Adding an event handler to a button is relatively simple. In your UIViewController subclass simply add a method similar to the one below, then in your interface builder select the viewcontroller and on the right side panel click the right most button at the top which looks like an arrow pointing to the right. under received actions drag the circle to the button that you want to perform the action.
-(IBAction)doSomething:(id)sender{
//code for doing what you want your button to do.
}
A separate way you could do it, if you still want to do it programatically is to do the same thing you're used to doing, except in your .h file add IBOutlet UIButton *buttonName; and in the right pane under outlets you'll see your button. which can then be referenced by name within the .m file.

Static table view - disclosure indicator to call phone number

I have a table view set to as static. it has 4 cells in it. the first two cells are mapped to another view so that works fine,
I would like the other 2 cells to either call a phone number or launch email. I do have the code for both of these functions already. I just dont know who to map the action of a cell selection to a function in the code. when I right click on the cell, I only see push action for segue but I want to control this in the code.
Open the storyboard file and click on the the Assistant Editor button in the top right of Xcode.
It should open up the header file to the view controller associated with the view. Now Ctrl and drag the cell you want to hook your code up to and drag it to the header file. This will create an IBAction for you. Now that it is hooked up, you can then call your method your created to handle the call or email.

Xcode issue - cannot connect button to object

I seem to be having an issue. The tutorial I am following from Apple's Dev Center says:
Control-drag a connection from the
Convert button to the
ConverterController instance in the
nib file window.
A black box will pop up similar to
the one we used to connect outlets.
Choose convert:.
Save the nib file.
I usually hold ctrl and drag the mouse from one object to another. However, when selecting a button from my User Interface and trying to drag to an Object in the xib window (this is all in the Interface Builder), the object will not highlight. It just won't let me do it!
Any ideas why this is happening?
you can use the "tree" map of all the objects in your nib file so it is easier to select one. this is helpful if they are on top of each other, hidden, or otherwise difficult to click directly. in xcode 4, there is a little triangle button along the bottom left of the nib view; if you click it, a sidebar opens with a text outline of all your nib's object. you can click the button in this list so it highlights, then control-drag to your file owner to attach it to a method you have written. the sidebar is also useful if you want to re-order objects in a view or subview, to make some on top of others.
Right click the file owner file a pop up will appear in front of you their you can see various action methods that you have in your project.
select a particular action method and then assign it to the appropriate button on which you want to call the appropriate function.