Bringing In An Outside Project Made Through Code To An Xcode Project Made With Storyboard - ios

I currently have an Xcode project that uses storyboard and I have an Xcode project in which I followed a tutorial and made a simple weather view controller. This Weather view controller uses CocaPods and requires that I use .xcworkspace whereas in my previous Xcode project (the one in which I am making via storyboard) I have been using the .xcodeproj file. I am trying to bring the weather view controller project into my storyboard Xcode project. Hopefully, I will have a button on one particular view controller link to the Weather View Controller that was initially created in another application.
I have asked a previous question in regards to a project like this but with no luck. The previous question can be seen here: combining-two-xcode-projects-one-with-code-and-one-without
In order to test the one answer I as given on that previous question I went about and created a blank Xcode Project from scratch, uploaded all of the .h and .m files, and then went into terminal (I am using mac) and programmatically the pods. The pods installed perfectly. I then put down a button and used the IBAction mentioned in the question I posted the link to above:
//When the button is tapped
-(IBAction)buttonTapped:(id)sender
{
//initialize the code only controller
WXController *WXController = [[WXController alloc] init]
//present the view
[self presentViewController:WXController animated:YES completion:nil];
}
I then ran the project and came across this error that highlighted this piece of code:
WXController *WXController = [[WXController alloc] init]
The error stated:
"No Visible #Interface for 'WXController' declares the selector alloc"
Just to make sure nothing else worked, I also tried to open the same project with .wcworkspace and came across the same error which I wasn't able to figure out.
I figured it must have been a button with the linking of the view controller with the button so not only did I post prior to this but I also did my own research and didn't have any luck as well. I checked out these posts:
How to combine two projects into one project
Loading a storyboard from a different Xcode project
Just to make the question I'm asking more clear, I included a link to the Weather Xcode Application I am trying to link to my storyboard application. You should be able to open the application here: Link
I was wondering: What exactly am I doing wrong that is providing me with the "No Visible #Interface for 'WXController' declares the selector alloc" error and even if this is fixed, am I missing something or should the view controller display properly.
Also, I have previously been using the .xcodeproj for my storyboard Xcode application. Is it necessary that once I bring this Weather view controller in, I must switch to .wcworkspace? and if so, what is the difference/ positive/ negatives of each?

Related

ios - loading decoupled view from nib file

I am having difficulty with something that seems to be trivial. I am following this project https://github.com/eppz/iOS.Blog.UIView_from_Xib and trying to implement the decoupled way of loading a view from a nib file. I was not able to get the desired result in my app (nothing shows up and I get no crashes either) so I did the following:
I took the project from Github https://github.com/eppz/iOS.Blog.UIView_from_Xib
I then proceeded to duplicate the files in the "decoupled" group and name it something trivial like "decoupled2". Basically I am creating a whole new class that stands on its own with its own nib file.
I then changed all of the internal tags and class references. Then I made sure that all of the new references were pointing to this new class.
At this point I added a 6th button to the main VC and made sure to call the right method for my new "decoupled2" class when this 6th button is pressed.
PROBLEM: Everything runs but the view from nib does not show up. Debugging view hierarchy shows nothing. Clicking the 5th button still works, so I didn't break the existing code. Why won't the newly created nib file show up?
This seems rather simple, just duplicate what already works in a project that already works and it will work...or not. What am I missing? Thank you for your help.
I have spent a few days on the problem already. Lots of research but nothing of use so far.
I re-did the task and it worked this time.
Maybe restarting Xcode 8.0 was the key or something else that is under the hood.

Integrating one iOS project into another iOS project [duplicate]

This question already has answers here:
importing one Xcode project into another
(2 answers)
Closed 6 years ago.
I have one existing project. Now i have developed one project with some new feature. Need to integrate the existing project to this. When i run this project it shows this app functionalities. On that one button click to show the existing project home page and continue that existing project. I need to enter the existing project and use that functionalities and UI whatever and exit from that to continue the current project. Kindly give me solution. If you don't know requirement ping me i will explain with detail.
You can possibly add the project folder of your project to your existing project and then once you are in your existing project on the click of your button you can do this,
UIStoryboard *sb = [UIStoryboard stoaryboardWithName:#"Main" bundle:nil];
This will load the storyboard of your new project, if you have made the project using xib then you can load the xib as well
Then you can,
ViewController *firstController= [sb instantiateViewControllerWithIdentifier:#"firstController"];
This will load the view controller of your new project, then you can do this to present this view controller,
[self.viewController presentViewController:firstController animated:YES completion:nil];
This will load your view controller now you can do what you want in your new project.
To comeback to your existing project you can set your new project delegate to be your old project and implement methods to comeback.
Hope this helps.

Error in Xcode 6 - view controller does not have an outlet named (subview)

I just got this error in one of my apps, and after checking some other apps the same error is happening. None of my IBOutlets and IBActions are connected anymore. When I recreate the outlet by control-dragging into the .h file, the outlet still displays the error in Connections Inspector > Outlets, saying (view controller) does not have an outlet named (subview). Before today I didn't have this problem, so is to do with Xcode 6? The view controller is referencing the correct class under Identity Inspector > Custom Class. I have deleted the derived data folder, removed the reference to the .h file, cleaned the project, and cleaned the build folder. None of that has worked and I can't progress with development until this issue is fixed.
Update: I just reopened the project after a couple of days and my outlets no longer have the exclamation mark next to them, and the 'easyLabel' outlet that I disconnected has reappeared. I didn't change anything, so I guess it's a bug in Xcode 6-6.1.
Update 2: This error came back. Exclamation marks next to every outlet. If I delete them I can't re-add them. Can't create new outlets. Also can't give a view controller a custom class. I really just want to make some progress on an app, but this issue keeps recurring. Really just can't stand it anymore. Any help would be appreciated.
Duplicate of: Xcode 6: can't connect any IBOutlet to ViewController but here's the trick:
You can also see that the link between the parent view and the custom class is broken (not visible anymore) which is a huge problem.
I had the exact same issue with the app i'm working on actually, updating Xcode from 5.xxx to 6.1. The workaround that worked for me was to remove the reference of every view controller and re-add them to the project... Unfortunately, in some cases, mine actually, all the connections get lost again when XCode is closed.
To everyone facing that issue, here's the (annoying) trick :
Step 1 : select both .h and .m view controller files
Step 2 : remove the reference of those files
Step 3 : re-add the files to your project tree
Step 4 : open the storyboard, eventually re-build the project and smile
I can understand those things could be reaaally annoying, but it worked for me... Hope it will help someone else !
I had the exact same problem and what was breaking my storyboards was the fact that my project was inside the folder /Dropbox (MyName)/projects/
Apparently something about the name of the dropbox folder with spaces and ( ) was BREAKING my storyboard completely, try what I did and move your project completely to another folder and see if that helps :)
I had the same problem, changed the class under identity Inspector > Custom Class to something else, saved it and then set it again to the correct one, after doing that the connections appeared normally.
I had this issue with a Swift UIViewController subclass. I had removed the original view that IB created for me, and added a new view—which I was unable to connect.
I went to the Identity inspector for the File's owner, and tried to re-enter it, thinking that maybe it had been modified somehow. Oddly, the class name did not autocomplete. It seemed like XCode was unable to actually see my class.
I tried removing and re-adding both the .swift and .xib files, to no avail. XCode would allow me to manually type in my owning class name, but it would not autocomplete. It seemed to think it didn't exist, or wasn't valid for this context.
Looking back at my code, I had something like the following:
extension SomeViewController {
func foo() -> Bool {
return false
}
}
class SomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
It compiles just fine, but on a hunch, I removed the extension. I saved the file, went back to the .xib, and was able to set the File's Owner identity with autocompletion again. I was also able to wire up the view.
It would suck if extensions always broke things of course, so I tried again, this time with the extension after the class:
class SomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension SomeViewController {
func foo() -> Bool {
return false
}
}
Everything still worked in IB. To sanity check, I moved the extension back ahead of the class definition, and things were again horked.
I took a look a the *-Swift.h generated by XCode, and at least relative to the affected class, there seemed to be no differences—regardless of where I put the extensions in the Swift file, they were always declared after the #interface definition for the actual class in the header.
So, long story short, in my case this was due to Swift extensions (I say extensions because my actual code has many) coming before the class definition. I moved them after the class definition, and the problem went away.
For me I had to remove the reference and add back to my project the -XIB- file for my view controller. Simply removing the view controller .h/.m did not reset the outlets, but removing the .xib and adding it back did!
I have this problem only with #protocol defined IBOutlets if I don't redefine them in the implementing class.
Probably the only thing we can do is file a bug.
Why dont you update your xcode 6.0.1 to xcode 6.1, Apple have fixed many bugs.
Download Xcode 6
Do you get the same issue if you connect the actions/outlets in Interface Builder instead of the assistant editor? For actions try control dragging from your object in IB to your first responder object (or whatever you have your class set to).
#robb actually discovered the fix for this, but the issue he found was that the group in the project that mirrored a folder on disk used a different case.
So if the project group was Broken/classone.m
and on disk it was broken/classone.m
Interface builder could not find the files. Renaming either the group or the folder to match case resolved the issue.
I was having the same issue but it was because i changed the name of the view controller in the Project Navigator to MapViewController but its name stayed the same (ViewController) in the code. once i changed it, it worked
I've had this same problem since using XCode 6.1, answers above didn't work for me. (removing/re-adding my class files, changing the class to something else and then changing it back. The only thing I didn't try was creating a new project from scratch).
I noticed by accident that my 'Application' placeholder within the MainMenu.xib had somehow got its class set to NSObject. Changing that to NSApplication seemed to clear the 'does not have an outlet named' problem from all of my other objects.
I updated my project from Xcode 6.x to Xcode 7.x about two months ago without any issues. But then this morning I ran into this bug. I tried pretty much everything on this page but nothing worked. But then Justin Middleton's solution gave me an idea.
When I switched my project from the 10.9 SDK to the 10.11 SDK, I decided I wanted my code to remain backwards compatible just in case I had to revert back to Xcode 6.2. So I put Preprocessor code around several of my object declarations, e.g.:
// This caused the (!) problem in Interface Builder
#if( MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_10 )
#interface CLChatWindowController : NSObject <WebPolicyDelegate, WebUIDelegate, WebFrameLoadDelegate>
#else
#interface CLChatWindowController : NSObject
#endif
...
// Removing all the Preprocessor code fixed the problem
#interface CLChatWindowController : NSObject <WebPolicyDelegate, WebUIDelegate, WebFrameLoadDelegate>
....
Once I removed all the Preprocessor code, the (!) characters in Interface Builder disappeared and everything went back to normal. Hope that helps someone.
Xcode 6.3.2. Similar issue. A project(s) that i've been working on suddenly 'disconnects' IBOutlets and shows the error
view controller does not have an outlet named (subview)
The project still builds and works and if you hover over the IBOutlets in code it thinks there are still connected.
I've nailed this down (at least in my case) to an issue with storing projects on dropbox (similar to an above post). The fix for me was super easy:
Drag the project folder off of dropbox to your desktop. Then drag the project back into dropbox.
This solution has fixed numerous projects with the issue.
Try to add the header file to the project, if it's missing.
I had this in Xcode 7.0.1 on a swift project. Specifically, tableview cell connections were broken (permanently) while other things still worked. Deleting derived data, rebooting etc - nothing worked.
My solution ended up being:
Close xcode project
Delete derived data for project (Window->Projects)
Rename the entire project/source folder, ie. project -> project-1
(Update source-management bookmarks like sourcetree as required)
Open project in xcode (from finder): notice that the storyboard and a few other files are in red. Delete the references, re-add them. Boom, it works.
Note that deleting the reference to the storyboard and readding it, even with deleted derived data, was not enough. The rename of the entire source folder was necessary for me.

Storyboard crashes Xcode when opened

Whenever I attempt to open up my storyboard, Xcode crashes with the following error report
The funny thing is, the app works fine in the simulator and builds without errors. What is causing this crash? I see two possible crashes:
Exception reason: UITableView dataSource is not set
, but that shouldn't make the storyboard crash right?
Details: Failed to compute auto layout status IBLayoutConstraint, IBUIButton, IBUIDatePicker, IBUITextField, IBUIView, IBUIViewController, and IBUIViewControllerAutolayoutGuide.
Which doesn't give much information at all.
I have been using a storyboard with Xcode 5 for some time, so the question does not appear to be related to moving from Xcode 4 to 5. I can open the storyboard as XML and I can open my iPhone storyboard just fine.
If you are using git, I would recommend reverting to a time before this problem started.
If you are not using git, and you are absolutely sure you did not edit the xml for the storyboard then I would say:
1)find the storyboard file using the finder.
2)copy it to your desktop.
3)go back to Xcode and delete the storyboard from your project, select "move to trash". 4)re-import the storyboard file into your project.
Ive had similar problems with Xcode 5 and either reverting using git or the steps above usually get me back up and running.
Exception reason: UITableView dataSource is not set
Details: Failed to compute auto layout status IBLayoutConstraint, IBUIButton, IBUIDatePicker, IBUITextField, IBUIView, IBUIViewController, and IBUIViewControllerAutolayoutGuide.
The errors described above lead me to think that one if not all viewcontroller(s) for the items listed above lost their connectivity to viewcontroller.h / viewcontroller.m files. I would make sure you have everything wired up correctly, and you can check this by making sure the items in your viewcontroller have a circle in the gutter (next to the line numbers) that is filled in (solid) if the circle is not filled in then it means your items are not wired up to your viewcontroller. I would post a picture of your .h / .m file of your viewcontroller so we can further investigate.
I ended up copying each view controller scene (in XML) into a new storyboard. Some view controllers could not be copied without the storyboard crashing so I had to recreate about 4 of them, but by and large I got the majority of my work back.
What you need to do is reopen the project again in Xcode 5 and then go to the storyboard. Then at the right side choose for "Identity and type" and then set "opens in" to Xcode 4.6 to be able to open it in Xcode 4.6. And disable auto layout, somehow when you open it in xcode 5 it asks you to update it, I think you did that without a thought, happened to me as well :)

Generating a view programmatically in iOS

Update:
Thanks for all the tips, everyone. The tutorial mentions that a XIB file is provided (which I don't have) so I'm doing something wrong in how I'm creating the the project.
I am following Apple's Core Data Tutorial for iOS. This tutorial has not been updated for ARC—apparently for Xcode 4, since it asks to "create a new project using the Window-Based Application template in the iOS section."
Since that option doesn't exist under Xcode 4.4.1, I looked around Stack Overflow and read that I should create an empty application. As per the tutorial instructions, I created no Storyboard or NIB file.
Other than updating the code for ARC (using strong in place of retain and not implementing the provided dealloc method), I'm confident that the code in my project matches that of the tutorial up to the end of the chapter "The Table View Controller." At this point, the tutorial says I should be able to run the project and get a view.
Instead, I get a blank, black screen.
Maybe my problem is too vague to solve here, but should I perhaps be using a different project template? Which one?
I have only two classes: a RootViewController and an AppDelegate. AppDelegate imports RootViewController and contains a UIWindow property. Again, there is no Storyboard or NIB in the project.
I can provide any code too if there's someplace specific to look.
If you want to check if your setup is correct do the following:
add a background color to your window
self.window.backgroundColor = [UIColor whiteColor];
make sure you tell the window to display itself
[self.window makeKeyAndVisible];
make sure your view controller is the window's rootViewController
self.window.rootViewController = myViewControllerInstance;
Choose Single View Application, and uncheck 'Use storyboards" field. The rest should go the same.

Resources