I'm trying to connect an outlet between a table view and the viewcontroller.h by using drag and drop. I'm using this tutorial. My problem occurs at the following instruction:
Select the Table View object and display the Assistant Editor using
View -> Assistant Editor -> Show Assistant Editor menu option.
Ctrl-click on the Table View object in the view and drag the
resulting line to the area immediately beneath the #interface directive in the Assistant Editor panel.
Upon releasing the line,
the connection panel will appear. Configure the connection as an
Outlet named tweetTableView and click on the Connect button.
I do not get the option to connect the two (by drag and drop). I have done it with a webview before and that all works correctly. The dragging also works for me in the storyboard itself but not when i drag to the viewcontroller.h file. Maybe its my storyboard setup; that is as follows:
Tab bar controller (Start point)
Navigation controller ---> Table view controller
View controller (with webview inside )
Could anyone please help me?
You have a Tab bar? Then, you must have another viewcontroller (let's say viewSecondViewController.h) associated to the second tab bar..
In that "ViewSecondViewController.h" you can drag and link...
Related
I am creating an app that requires notifications. I created a settings page with a switch to toggle notifications for the application. I tried to link the switch to ViewController2 using an #IBAction, but it keeps connecting the object to Exit, instead of ViewController. I am getting really frustrated because the #IBAction won't stay connected. I am not sure what is going on, but if I could get help that would be amazing.
The images are linked down below to Imigur.
This is the connection to ViewController2
This is what occurs when I connect the IBAction to ViewController2
You can see there is no action option for the connection in this image.
When you attach #IBActions (or #IBOutlets), you do not want to attach them to Exit on the View Controller.
Follow these steps to add an #IBAction:
1) Make sure your View Controller's class is linked to your file, then go into the Assistant Editor making sure you selected Automatic.
2) Hold Control (^) and drag the button to your ViewController class.
3) Add the button as an #IBAction. - It's also recommended to use UIButton as the sender, instead of Any.
It should look like this:
If you have questions, let me know!
The problem might be that you are supposing you can form an action connection from a UISwitch in the scene of one view controller to a different view controller. You can't. You can form outlets and actions only between a view controller and the interface inside the same scene of the storyboard.
Click on the top bar of your problematic ViewController (the overview of what is getting displayed on screen), click the top left icon (called View Controller).
On the right click "Show The Identity Inspector" icon and you should see class. Change the text to 'ViewController'. Hopefully it should auto fill.
This will solve the problem.
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.
I have 4 different viewcontroller and these are connect with 4 tabs in UITabBar. I have to write respected code in each viewcontroller but I noticed the code which is written in each viewcontroller is not loading. Where to write code in each viewcontroller when it is loaded after selecting tabs in uitabbar?
You need to create a view controller file for each view (simply right click on the left where the files are and do New File -> UiViewController).
After that, in the Storyboard, select the view, and in the properties, change from the default view controller to the custom one you have created (this is the third icon on the right panel, under "Custom Class"). The UITabBar should handle switching the views, and your code will make the views run uniquely :)
I started an "Empty Application" template, this means that I had to add my own storyboard file. Problem is, it is completely blank, and I can't figure out how to get the first view on there, so I can start designing my interface.
Anyone know how to get that first view on there?
When you create a new Storyboard file, all you need to do is click/drag the UIViewController object from your right hand side of tools into your Storyboard and then you're all set to begin work on your new Storyboard.
Just in case you can not start from scratch :
Select your View Controller
Open the Attribute inspector (right pan by default)
Go to View Controller section
Select Is Initial View Controller checkmark of the Initial Scene option
In the latest version of Xcode (12.2), this is how you can add initial view to story board
Click on + Icon,
search "View Controller", Drag and drop View Controller.
Go to Edit->Show Library then drag and drop a type of View Controller that you need.
All,
I found the code in Matt Gallagher site ( http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html ) for this really neat design for a Table View... Im very new to Cocoa and Im having a hard time figuring out how to wire the darn thing in IB...
I loved the design and wanted to use something similar in a more complex structure... Nav Bar / Tab Bar with a few other views / TableView for the data in the first view... I found lots of tutorials to do that and got it working... When I tried to use that design in my project, things went crazy... in My MainWindow.xib I cant have a UIView where the arrow is pointing...
the nib looks like this:
Tab Bar Controller
Tab Bar
Nav Controller
Navigation Bar
Table View Controller
Table View
---->>>> (UIView for the backgroundImage )
Navigation Item
Tab Bar Item
UIView Controller
Tab Bar item
Window
can anyone guide me in the right direction??
Thanks !!!
It sounds like you're not having issues with the table view as much as the construction of the hierarchy around the table.
Instructions for creating the hierarchy would be as follows. I think you've diverged at around step 9:
Start with new copy of the default iPhone "View" template
Throw away the view controller class.
Open the MainWindow.xib and delete the view controller there too.
Find the controllers in the
Interface Builder library palette (they're
the yellow spheres at the top of the "Cocoa Touch" library in "Objects" mode whose icons contain
other objects).
Drag the tab view controller into
your MainWindow.xib file at the top
level.
Expand the tab view (triangle next to its name in the list view of the xib)
Drag a navigation controller into your expanded tab view (if this works, it should appear as one of the tabs along with the two view controllers that are there by default)
Expand the navigation controller
Drag a view controller (not a table view controller) into the navigation controller. It should appear as the content of the navigation controller.
Select the view controller (single click).
Press Command-4 (or select "Identity Inspector" from the "Tools" menu).
In the "Class Identity" popup menu, select EasyCustomTableController (this assumes that the current xib file is part of an Xcode project and this Xcode project already has EasyCustomTableController added to it).
Add a UIImageView to the view controller's view (this is your background image)
Add a UITableView to the view controller's view (this is your table). Add this view so it is after (and hence on top of) your image view.
There should be a tableView outlet on the view controller. Connect this to the table view.
Connect the app delegate's viewController to the tab bar controller (back in Xcode you can optionally change the type of this property to UITabViewController)
Should work.
The trick is that UITableViewController can't be used if you want the view to contain more than just a table. For this reason, you must use UIViewController and recreate the functionality that the UITableViewController adds. See here for how this is done:
http://cocoawithlove.com/2009/03/recreating-uitableviewcontroller-to.html
Thank you Matt (kind of cool that you answered)!!
I really appreciate the help... I've been messing around with it and got it to work using a UIViewController in another view (being created from the tableview)... Once I had the UITableViewController in the navigation I dropped the imageview & used a gray color; it looks great!! The initial screen has the rows big enough that scrolling is not an issue... I will go back and try to change that now...
I do have to say that IB is by far the most challenging step in app development for a newbie coming into Cocoa Touch !!! Yikes!