Why can I not wire up my IBOutlets in storyboard? - objective-c

I have a ViewController that has a couple of IBOutlet properties defined for UITextView. In the storyboard I have assigned my viewcontroller to the custom view controller. When I cntr + click on the viewcontroller I can see my two IBOutlets. When I try to drag them to the UITextViews on the storyboard they will not highlight and cannot be assigned.
I'm new to xcode 4.
Here is the property definitions from the viewcontroller:
#interface CreateUserViewController : UIViewController<UITextInputDelegate>
#property(nonatomic,retain) KeychainItemWrapper *keyChainWrapper;
#property(nonatomic,retain) IBOutlet UITextView *userNameTxt;
#property(nonatomic,retain) IBOutlet UITextView *passwordTxt;
These properties are synthesized in the implementation. I can assign each of the textfields' delegate to the viewcontroller without a problem. Am I missing any step?
Thanks

Make sure that the views you're trying to connect really are UITextViews and not UITextFields. It's not difficult to get them mixed up.

Related

UITableView within a UIViewController - Data doesn't load

I know that there are several posts around the www, but sadly I don't get the tableView to be loaded.
here is my code:
.h file
#interface ViewControllerSzenenLichter : UIViewController<UITableViewDelegate, UITableViewDataSource>{
IBOutlet UITableView *tableView;
}
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#end
I connected the IBOutlet with my tableview in the Storyboard
.m file
#interface ViewControllerSzenenLichter ()
#end
#implementation ViewControllerSzenenLichter
#synthesize tableView;
somewhere in the code I try to execute
[self.tableView reloadData]
which is executed(checked by Breakpoint)
but the method numberOfRowsInSection or numberOfSectionsInTableView are never called!
As mentioned I found a lot of tutorials in the web, but I can't solve the Problem.
thanks
Your child tableView is basically a cell of your parent tableView.
So, unless you reload your parent tableView, the cell will not update, and hence, the child tableView will not be plotted.
[childTableView reloadData];
[parentTableView reloadData];
EDIT :
And #Desdenova is right. Make sure you set your delegate and data source to self or whatever class manages the tables.
In the storyboard Right click over the table you will see datasource and delegates as the first two options.Connect both to the viewcontroller (same as you did for outlet connection) and run again.
The final table connections will be like this
It seems, you connect one IBOutlet and use another when reload data: You have two ivars tableView (you create it manualy) and _tableView (created compiler and links with #property (nonatomic, retain) IBOutlet UITableView *tableView;), I don't now which one will be shown as TableView property of file owner in InterfaceBuilder. Try remove IBOutlet UITableView *tableView; ivar and reconnect Table in IB
First of all, make sure you are setting delegate in xib file or implementation file for your table. If still not working, check the code where you are reloading table. If main thread is busy doing something else, it will not call any of the delegate method of UITableView. So when the code finishes, then reload tableview.
Connect your TableView to the File's Owner by the delegate and datasource...
I think your problem will be solved. Here is a picture for your batter understanding...

IOS6 - getting IBoutlet's frame from viewDidLoad returns 0

I'm working on storyboard with Autolayout. I have a viewController (i.e. myController) and I dragged in it a UIView (i.e. myView).
in myController.h I declared an IBOutlet for myView:
#property (weak, nonatomic) IBOutlet UIView *myview;
and later I have associated this with my UI over storyboard (ctrl+dradding from myController's outlets).
The point is that I thought I could see myView's size from myController viewDidLoad Method:
NSLog(#"pag h:%f e w:%f",myView.frame.size.height, myview.frame.size.width);
But both of these outputs are 0. Where I could possibly be wrong?
If you are using autolayout, then at viewDidLoad layout has not happened yet. The frames at this point are still equal to CGRectZero when the views are loaded from the storyboard.
Log this again in viewDidAppear: and you will see the frame after layout is complete.

Access a UITextField in another UIViewControllers view

This is how I use a XIB view controllers view as a subview in the MainViewController:
UIViewController *nameController = [[NameSubViewController alloc] initWithNibName:#"NameSubViewController" bundle:nil];
nameSubView = [nameController view];
[self.view addSubview:nameSubView];
The nameController view contains a UITextField property. Can I somehow access this property from MainViewController?
EDIT:
If I create a property for the textField in the View Controller too, I'm still not able to get it in MainViewController. Think it's because of the UIView subclassed causing problems?
NameSubViewController.h:
#import <UIKit/UIKit.h>
#interface NameSubViewController : UIViewController
#property (nonatomic, strong) IBOutlet UITextField *textField;
#end
NameSubView.h:
#import <UIKit/UIKit.h>
#interface NameSubView : UIView
#property (nonatomic, strong) IBOutlet UITextField *textField;
- (IBAction)textFieldReturn:(id)sender;
#end
Connections in IB for NameSubViewController:
Connections, NameSubViewController
Connections in IB for NameSubView:
Connections, NameSubView
Did you create an outlet for the textfield in your nameController? Do that, and then you can retrieve the value using
nameController.textField.text
In the nib file, click on the file's owner icon (on the left of the nib), and set it's class to your UIView's subclass using the inspector on the right.
Why are you adding view from Controller A in Controller B. Isn't it better that you create a view by only using its xib file and add that view to your controllers view.
For accessing field, you can assign a tag to your textfield, and where ever in your code you need it, call
self.view viewWithTag:<#(NSInteger)#> method.

Can't link datasource of two tablesView

So I have two TableView in one view of an iOS app. I have connected the delegate of both tableViews to the ViewController, and the app works. The problem is when I connect to the viewController the dataSource, so when I run the app Xcode returns to me a SIGABRT.
Anyonoe knows what am I doing wrong?
Make sure that the tableViews are not pointing to delegates that don't exist anymore. For example you might have deleted a delegate from your code but forgot to delete the connection from the tableview to the delegate.
Can you post your code?
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
}
#property (weak, nonatomic) IBOutlet UITableView *Listview;

Modifying properties of a view controller form another view controller

In my project, there are two view controllers - let's say firstViewController and secondViewController. The second view controller has a button, and I want to make sure when the button gets pressed, the second view controller is telling somehow the first view controller - "hey, I got pressed, do something!", and it will do something, like changing a label. How is this possible to perform? Thanks in advance. Some code :
#interface firstViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *textLabel;
#end
#implementation firstViewController
#synthesize textLabel;
#end
#interface secondViewController : UIViewController
-(IBAction)buttonPressed;
#end
#implementation secondViewController : UIViewController
-(IBAction)buttonPressed{
// Hey, I got pressed! Set the text on textLabel to "OK"!
}
#end
This is a very simple case of delegation and protocol mechanism of objective-c..
have a look at this tutorial which will explain you how its done.. you can do this via notification also but that is not usually advised...(because notification is usually used when the receiver is unknown , like in the case of UIDeviceBatteryLevelDidChangeNotification you don't exactly know which view controller wants to know about this.)
I'd first consider what the button press means. Does it change the state of the model?
Say your model is an int, and the button increments it. The view controllers wouldn't message each other about that, they would just both observe the state of the model. (The one with the button could change the state, too).
Thinking about it this way, the solution probably isn't delegation. It's probably notification or KVO.
See the answer to this question: Passing data between two view controllers via a protocol
However, ask yourself if you really need a protocol here. If it is just between this classes or just about the question of accessing data of a class or sending information to a class then that is what the interface of a class is made for.
#interface firstViewController : UIViewController{
UILabel *textLabel; // I personally alway add IBOutlet here too, but I think that is not required.
}
#property (weak, nonatomic) IBOutlet UILabel *textLabel;
#end
And in SecondViewController.m:
#import "FirstViewController.h"
#implementation secondViewController : UIViewController
-(IBAction)buttonPressed{
// You will have to have a properly set instance variable firstViewController
[firstViewController.textLabel setText:#"OK"];
}
#end
So your second view controller needs to 'know' the first one. One way of achieving that is defining
FirstViewController *firstViewController;
as property and set it from wherever the second view controller is created and the first one is already known. How to do that exactly depends very much on the architecture of your app.