Xcode displays outlets from multiple projects - ios

I have a Workspace in which there are two Projects. Both projects contain a ViewController with the same name, but with different IBOutlets. This all works fine while coding, but 'Interface Builder' gets confused.
An example of the situation:
The contents of both FGViewControllers:
-- MyApp1
#interface FGViewController : UIViewController
#property (nonatomic,weak) IBOutlet UIView *myApp1Outlet;
#end
-- MyApp2
#interface FGViewController : UIViewController
#property (nonatomic,weak) IBOutlet UIView *myApp2Outlet;
#end
When you now open Main.storyboard (either one), in the Connection Inspector both outlets are shown:
Is there a way to have Xcode only show the outlets that are located in the project of the storyboard you're editting?

Related

Sharing same properties of ViewController for iPhone Stroryboard and iPad Story Board

I'm developing a universal application.
in the first view, I have the login screen for the user.
In iPhone storyBoard, I have added 2 text field and one button( login check).
I have added properties in ViewController.h file by dragging those objects(Ctrl key + Dragg) to .h file.
I have added code for login check and it is working fine for iPhone.
This is the code in ViewController.h
#property (strong, nonatomic) IBOutlet UITextField *txtUserId;
#property (strong, nonatomic) IBOutlet UITextField *txtUserPwd;
#property (strong, nonatomic) IBOutlet UIButton *btnLogin;
In the iPad storyBoard, I have added 2 text field( userid and password) and i button for login.
So now, I want to bind those objects with the veriable which I declared already in ViewController.h file in case of iPhone.
My questions:
1. What is the right way to bind properties for both storyboard?
2. Am I on the right direction or should I think in a different way to do it?
I am new with iPhone development. Please help.
Thanks.
--Amin
Give your custom class name to storyboard from storyboard utility.
Ensure to link both the storyboards with your Login class. Now go to iPad storyboard, right click the view components and drag them and hover on to the properties you have declared already.

The storyboard is automatically copied to the new project

I have a project in Xcode, lets name it A, in which I have a story board and several views. I only need part of project A. Hence, I made a new project, B, and made a new UIViewController, with xib, and copied the two UIViews from project A to B.
It looks like this now, where RPM Display and Speed Display are copied (by dragging from xib) from A to B.
AnalogDisplayContainer belongs to the class PD_AnalogDisplayContainer, and we have two outlets in class PD_AnalogDisplayContainer:
#property (nonatomic,assign) IBOutlet PD_AnalogDisplay* speedDisplay;
#property (nonatomic,assign) IBOutlet PD_AnalogDisplay* rpmDisplay;
which are connected to the respective views in xib. (We have exactly the same code in project A.) These UIViews have some UILabels as well, which are automatically copied in project B, and I need them as well. You see them here:
Up to here, the description of what I did. Now, the problem:
I have three outlets in class PD_AnalogDisplay.
#property (nonatomic, assign) IBOutlet UILabel* unitLabel;
#property (nonatomic, assign) IBOutlet UILabel* digitalIntegerValue;
#property (nonatomic, assign) IBOutlet UILabel* digitalFloatValue;
However, so strangely, when I click on the small point beside these outlets, it shows me the connections to story board,
and when I click on the connection, I see the whole storyboard and views from project A.
In addition, these connections are not shown when I click on xib.
I searched in project B, there is no storyboard, or all these things I see in the previous picture, in form of code. So I don't know where it all come from. And I get the run time error:
loaded the "RPMViewController" nib but the view outlet was not set.
Yes, it brings previous reference wherever you copy it.
It is happening because the class name is same in project A and B.
Create class name in project B other than class name in project A or slightly change variable name.
Assign that class to your xib file.
You must recreate the IBOutletes from xib file.
Just copy the interface components not the code in .h file.
Observations:
When I move project A to another location makes trick, reference destroyes.

Interface Builder outlets managing

I want to create UIViewController subclass that will be container for two other controllers and it has properties
#property (nonatomic, strong) UIViewController *firstController;
#property (nonatomic, strong) UIViewController *secondController;
then i wanted to connect these properties via interface builder to instantiate them automatically. But if i just make them IBOutlets
#property (nonatomic, strong) IBOutlet UIViewController *firstController;
#property (nonatomic, strong) IBOutlet UIViewController *secondController;
i cant connect other controllers. but UINavigationController has property rootViewController and we can connect other controllers in IB. if it's possible to make such trick in custom controllers please help
You can't connect outlets from one controller to another controller -- outlets only work within a controller, not across controllers.
If you want a controller to be a container for two other controllers, you should drag two container views into your controller's view in the storyboard. You will automatically get two controllers connected to those container views with embed segues.
It should work the way you have it now. Are you sure you're adding View Controller objects in your XIB? Your UIViewController subclass xib file should look like this:
Then you should be able to right-click and drag the connections for firstController and secondController.

xcode IBOutlet won't connect to codes

I am using xcode 4.3
I have a huge problem:
I started creating an application using storyboard for the ipad. At first i added my objects in interface builder, and then I dragged the blue line to the .h file and xcode made the connection and created a:
#property (strong, nonatomic) IBOutlet UIButton *button1;
with the filled up circle.
But after a few days, I tried to add a UIScrollView. I added the object to the storyboard, and dragged the line, but it would not connect and create a property. So I made first the codes,and tried to link, but same problem. So I deleated the scroll view and inserted again a button and lable. BUT NOW ANY OBJECT WON'T LINK TO THE CODES IN ANY WAY!!! WHY? To solve the problem I have to start again from the biginning!!
I create:
#property (strong, nonatomic) IBOutlet UIButton *button2;
drag the line: NO
drag to view controller: NO
did the opposite: NO
WHY???
You need to make the scene an instance of class ViewController instead of UIViewController, which is the default. You can change this in the identity inspector (third tab in the utilities)
If you're trying to drag the line to anything other than a button you're not going to have any success.
If you want to drag the line to a scrollview, you need to change the declaration to
#property (strong, nonatomic) IBOutlet UIScrollview *scrollView;
//^^^^^^^^^^^^ this type determines what it links to in interface-builder

How to convert a project based on a master detail controller template to a simple model view controller template?

I started to create a project from the master detail template and realize that my main controller should be a simple mvc. Is there any simple method to do the conversion beside recreate a project from scratch with a mvc template? What should be edited then?
The templates just set up your appDelegate with the proper elements. You could edit your appDelegate quickly, but unless you have a really compelling reason to edit the existing project it would likely be faster to just recreate the project.
With the master-detail template the appDelegate will have these properties (and code in the .m implementing them):
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UINavigationController *navigationController;
#property (strong, nonatomic) UISplitViewController *splitViewController;
The standard template will have these (plus the implementation code):
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
The implementation file of the appDelegate will also be slightly different due to the NavigationController and SplitViewController in the master-detail. You can just change these files around and update your xib files, but again, it's probably just as fast to start a new project.

Resources