how to add a ready-to-use project ( created and started with application delegate but without xib,nib) to another project - xib

I have a ready-to-use project ( created and started with application delegate but without xib,nib). Now I want to invoke and start it from another project.
But I can't use initwithnib, how can I include and start this ready-to-use project from another project?
More specifically, how to add and integrate Apple's Sample code " TableViewUpdates ( TVAnimationsGestures.xcodeproject ) " which only has its own appDelegate and Mainwindow.xib file to my own application? thanks!
Or can you add a xib file to the Apple's Sample code " TableViewUpdates ( TVAnimationsGestures.xcodeproject ) " so that I may use initWithNib in my another project to invoke and run the sample code. thanks !

I work on Xcode 4.3.2.
Create sigle view sigle view app.
Expand all folders in MoviePlayer example. Select all files, except info.plist, main, Frameworks, Products folders, readme.txt, MoviePlayer.project. Copy them to new empty project. Don't forget to check "add to target".
In target's build phase tab added MediaPlayer.framework (in link Binary with libs)
Copy all object from MainWindow.xib to your own xib for your viewController.
Than in ViewController.h :
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITabBarController *tabBarConroller;
#end
Connect your tabBarController from ViewController.xib to the property.
Than in ViewController.m :
#implementation ViewController
#synthesize tabBarConroller;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:tabBarConroller.view];
}
- (void)viewDidUnload
{
[self setTabBarConroller:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
...other appdelegateMethods ...
#end
7. Check that all objects in viewController.xib has necessary outlets.
6. Edit > Refactor > Convert to ARC. (next, ok...)
It's done.

Related

TodayViewController class in iOS Today widget not being read?

My TodayViewController class is implemented as follows:
#import "TodayViewController.h"
#import <NotificationCenter/NotificationCenter.h>
#interface TodayViewController () <NCWidgetProviding>
#end
#implementation TodayViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(#"yeehaw");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResultFailed
// If there's no update required, use NCUpdateResultNoData
// If there's an update, use NCUpdateResultNewData
NSLog(#"gitalong");
completionHandler(NCUpdateResultNewData);
}
- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets{
NSLog(#"yowza!");
return UIEdgeInsetsZero;
}
#end
Basically this is the boilerplate implementation that XCode provides when you create a Today target in your app. The only changes I've made are to add some NSLog() calls in each of the functions, and to remove the default left margin in the widgetMarginInsetsForProposedMarginInsets() function (as per the method in this SO thread).
However, when I look at the system log output, none of my NSLog statements are being output, and the default left margin has not gone away, so I'm thinking that for some reason, my app is not reading/processing the TodayViewController class at all, even though it is otherwise displaying my MainInterface storyboard correctly.
Does anyone know why this might be happening?
UPDATE
A detail I forgot to mention is that the MainInterface.storyboard file I was using to implement the interface was copied into this project from another version of the same project. I was able to fix this problem by recreating the entire project from scratch and recreating the interface from scratch as well, so the MainInterface.storyboard file I used in the "working" project was the original one generated by XCode. While this strategy fixed my immediate problem, I still don't understand why the storyboard file that I imported from another project didn't work. This poses a problem for interface reuse. I'd still like to know how to link an imported storyboard file to a custom ViewController.

How to import another view controller header file when I use Objective-C category?

When I want to transition from one view controller to another, I import the second view controller's header file into my first view controller's header file, by writing #import "SecondViewController.h". However, since I already defined UIColor category in my first view controller, when I try to import the second view controller, I enter the following error: Duplicate interface definition class for SecondViewController.
Here's my FirstViewController.h:
#import
#import "SecondViewController.h"
#interface FirstViewController : UIViewController
#end
#interface UIColor (ColorWithInt)
+ (UIColor *)colorWithR:(CGFloat)red G:(CGFloat)green B:(CGFloat)blue A:(CGFloat)alpha;
#end
I didn't meet any such errors so far when I develop this app, so it's definitely this category that is causing the issue here. So is it feasible to use category when I want to import another view controller class? Or are there any alternative ways to extend UIColor? I just want to define a function that takes RGB as 0 ~ 255 integer, not 0 ~ 1 floating values that UIColor uses on default.
I use iOS 7 and Xcode 5.
You might #import "SecondViewController.h" twice, just check FirstViewController.h/m file if both did that.
I have a feeling you're using this
#interface
instead of
#implementation
in your .m file.
Self Answer
I found out that the issue is not related to either FirstViewController or SecondViewController - let alone the category; it's because I imported almost all class' header file in AppDelegate.h in order to initialize the relationship among UITabBarController, UINavitationController, RootViewController, and Core Data and its lots of required properties. I didn't know that when I import a class in AppDelegate.h I cannot import the class at some other class's header file. Delete #import "FirstViewController.h"; and #import "SecondViewController.h;" in AppDelegate.h and I find my app being build properly now. Thanks to those who left comments in this post.

NSUnknownKeyException in Apple's HelloWorld tutorial

I'm a noob to iOS development, so am following the HelloWorld tutorial here. I've got to the stage where I'm testing the app after adding the button, text field and label. I have followed the tutorial to the letter as far as I'm aware and I'm getting this error when I run the app:
2013-07-13 15:26:39.629 HelloWorld[1304:11303] * Terminating app due
to uncaught exception 'NSUnknownKeyException', reason:
'[<HelloWorldViewController 0x7566000> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key label.'
* First throw call stack: (0x1c90012 0x10cde7e 0x1d18fb1 0xb79e41 0xafb5f8 0xafb0e7 0xb25b58 0x22f019 0x10e1663 0x1c8b45a 0x22db1c
0xf27e7 0xf2dc8 0xf2ff8 0xf3232 0x423d5 0x4276f 0x42905 0x4b917 0xf96c
0x1094b 0x21cb5 0x22beb 0x14698 0x1bebdf9 0x1c13f3f 0x1c1396f
0x1c36734 0x1c35f44 0x1c35e1b 0x1017a 0x11ffc 0x1f9d 0x1ec5)
libc++abi.dylib: terminate called throwing an exception
The code generated in HelloWorldViewController.m is:
#import "HelloWorldViewController.h"
#interface HelloWorldViewController ()
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (weak, nonatomic) IBOutlet UITextField *textField;
- (IBAction)changeGreeting:(id)sender;
#end
#implementation HelloWorldViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)changeGreeting:(id)sender {
}
#end
And in HelloWorldViewController.h:
#import <UIKit/UIKit.h>
#interface HelloWorldViewController : UIViewController
#end
I tried using this answer but I can't see an XIB file (I think because I'm using a Storyboard?) and I can't see any obvious discrepancies in the VC.
Please help.
A storyboard is a single file that encapsulates a collection of XIB files. Each "scene" in a storyboard represents what would otherwise be a single XIB file.
In the storyboard...
(1) Select the View Controller in the relevant scene.
(2) Open the Identity Inspector (third tab in the right-hand Utilities pane). Check that the view controller's class is correctly set to HelloWorldViewController.
(3) check that the View Controller's IBOutlets are correctly wired up to the correct views. (Ctrl-click on each view and check it's settings in the HUD).
'Wiring up' entails CTRL-dragging from your viewController to the relevant view in your storyboard scene. A list will appear of appropriate IBOutlet properties to select.
These properties can be placed either in the interface declaration in the .h file or in a class extension in the .m file.
An interface declared as #interface (in the .h file) is public; A class extension declared as #interface() (usually in the .m file) is private to the class (although nothing is completely private in Obj-C). Class extensions are useful for declaring private properties, or properties that are publicly readonly and privately readwrite. See the apple docs. They used to be good for declaring private methods, but now this is redundant: methods only need declaring if we want to make them public.
A good rule of thumb is wherever possible, keep your declarations in the class extension and out of the .h file. These days this should only apply to properties as method declarations are not required unless making them public.
You mentioned that you fixed your problem by moving your property declarations from the class extension to the public interface. This is puzzling, as both locations are normally acceptable for this use.
I removed all referencing outlets and actions which you can see at connection indicator while selecting objects one by one at storyboard workspace, and deleted some codes added automatically by xcode.
And then I made them by following tutorials again. finally it worked fine.

Why doesn't this local html page load?

I have the following:
#interface HelpViewController : UIViewController <UIWebViewDelegate>
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#end
And for the same view controller
#implementation HelpViewController
#synthesize webView = _webView;
- (void) viewDidLoad
{
[super viewDidLoad];
NSString *filePath=[[NSBundle mainBundle] pathForResource:#"test" ofType:#"html"];
NSLog(#"%#", filePath);
[self.webView loadData:[NSData dataWithContentsOfFile:filePath]
MIMEType:#"text/html"
textEncodingName:#"UTF-8"
baseURL:nil];
}
And a basically empty nib to go with this view controller. The file's owner is has an outlet to view. The file path comes back OK. But nothing shows up in the view. I think the problem is that IBOutlet UIWebView *webView is not connected to anything, 'cause I don't know what to connect it to. Is that the problem? If so I need to know what to connect it to; otherwise, I need any kind of help! Thanks!
EDIT: Forgot to mention that I think I have the same problem as this SO Question where it says to connect the outlet, but doesn't say to what.
Normally when you add a new file to the project xcode will automatically add it to the "Copy Bundle resources" section of your target.
Sometimes, if you are collaborating with another person the project.pbxproj will get out of sync and this entry will get removed. The fix is to ensure that all the files in the Resources folder (that are required in the release) are also present in the "Copy Bundle resources" section, and if it isn't just drag it from the resources to that section.
In your case drag check if your html file exists in copy bundle resources. Check that in the project > target > build phases > copy ressources to bundle.
Alright, after a lot of study of other SO pages and some non-SO material, I figured out that I had not added a web view from the library to the nib. So that's why I couldn't hook it up. So I made sure first that the 'regular' view was hooked up, added the web view from the library and hooked up it's view. Then I needed the following additional line in my code:
[self.view addSubview:_webView];
to viewDidLoad. Whew!

RootViewController cannot use 'super' because it is a root class

While going through a tutorial which uses a navigation based- application, I decided to create a Navigation-Based Application with my 3.2.6-Xcode and open it with Xcode 4.2 for following the tutorial with that version.
But when I open the same project in Xcode 4.2 (without changing or adding any code), the 4.2 Xcode gives me 2 errors saying:
RootViewController cannot use 'super' because it is a root class
Right now, my Xcode has 4 class-files: RootViewController.h, RootViewController.m, SaveUpAppDelegate.h and SaveUpAppDelegate.m. The error is in RootViewController.m:
- (void)dealloc {
[super dealloc];
}
and
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
I already searched through the internet and found this discussion (http://stackoverflow.com/questions/10113669/xcode-4-3-2-gives-error-cannot-use-super-because-it-is-a-root-class) and they say that the reason might be that the controller is that the developer forgot the superclass in the #interface line. That doesn't fit to my case, because I (or better: Xcode 3.2.6) didn't forget the superclass in RootViewController.h...
#import <UIKit/UIKit.h>
#interface RootViewController : UITableViewController {
}
#end
right now, I commented those critical lines out and it works fine, but I'm sure, I'll need those lines since most of the automatic created lines in the m-file are done with [super ....].
How to solve the problem?
My resolution was more simple. There was a misspelling in the #import "ClassHere.h" in the .m file. This resolved the issue I had.
Clean. It's an option under "Run". It removes all the build files that are automatically generated.

Resources