No visible interface for #LWWFirstController declares the selector initWithStyle - objective-c

I am getting the error "No visible interface for #LWWFirstController declares the selector initWithStyle". I have written similar code for setting up my Navigation Controller and it worked fine, but I can't seem to find what is causing this error. I have looked on StackOverFlow for similar issues but none fit, I'm using the correct method for it. Does anyone have in clue? Here is my code below.
#import "LWWAppDelegate.h"
#import "LWWFirstLevelController.h"
#implementation LWWAppDelegate
#synthesize window = _window;
#synthesize navController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
LWWFirstLevelController *first = [[LWWFirstLevelController alloc] initWithStyle:UITableViewStylePlain];
self.navController = [[UINavigationController alloc]
initWithRootViewController:first];
[self.window addSubview:navController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

It basically says you didn't implement initWithStyle method in your LWWFirstLevelController.
Are you sure it is a subclass of UITableViewController?

Related

OS X how to designate startup viewcontroller

I am developing a simple browser project on mac, i didn't use the default viewcontroller.
Instead, I write a viewcontroller class BrowserViewController.
and write follow in appdelegate
#interface AppDelegate()
#property (nonatomic, strong) BrowserViewController *browserController;
#end
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
self.browserController = [[BrowserViewController alloc] init];
[self.window makeKeyWindow];
[self.window setContentView:self.browserController.view];
}
#end
But when the app start up it lead to the default viewcontroller not the BrowserViewController. I really don't know the reason.
Thanks for the help, i have solve this problem. My solution is like this:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//set the frame of the window fit to the device's frame
//
self.window = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO ];
//
//
self.browserController = [[BrowserViewController alloc] init];
//set contentView
//
self.window.contentViewController = self.browserController;
//this is setting global backgroundColor of the window
//
self.window.backgroundColor = [NSColor whiteColor];
//this means the window is the window that will receive user interaction.
//
[self.window makeKeyAndOrderFront:self];
//[self.window makeKeyWindow];//NOTE: This is not working.
}
You can select Is Initial Controller in the storyboard.
Sounds like you're looking for (inside your didFinishLaunchingWithOptions method):
self.browserController = [[BrowserViewController alloc] init];
[self.window setRootViewController: self.browserController];
[self.window makeKeyAndVisible];
If you want it programmatically:
Note
This is for iOS, but the logic are identical. Hope this will be useful for some reason.. :)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//set the frame of the window fit to the device's frame
//
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//what you have above is correct
//
self.browserController = [[BrowserViewController alloc] init];
//you can also directly set it like
//
BrowserViewController *mainView = [[BrowserViewController alloc] init];
//this is the most important, you need to set the window's rootViewController
//
self.window.rootViewController = mainView;
//this is setting global backgroundColor of the window
//
self.window.backgroundColor = [UIColor whiteColor];
//this means the window is the window that will receive user interaction.
//
[self.window makeKeyAndVisible];
return YES;
}
Hope this is helpful and informative.. Cheers! :)

Loaded Xib file but nothing appears

I just started to learn objective-C and am having issues with transitioning between loading a view (directly) to using a XIB as rootViewController. Currently I am trying to load my xib file into a view controller object. While it compiles without any problem, my simulator comes up blank (except for basic interface, time and battery fuel gauge). I also made sure to set my XIB into class BNRReminderViewController and set the view and respective button/objects. (I also imported my class BNRReminderViewController.h to my .m file)
Below is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
NSBundle *appBundle = [NSBundle mainBundle];
BNRReminderViewController *rvc = [[BNRReminderViewController alloc] initWithNibName:#"BNRReminderViewController" bundle:appBundle];
self.window.rootViewController = rvc;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
I think what is happening is that my BNRReminderViewController.xib file is not within the mainBundle so when I init with the NSBundle object nothing loads which is why I am getting blank screen. I am new to objective-C so I do not really know how to deal with this as many other languages just import a .h or directly read the file. please help.
You can check if your hypothesis about the NSBundle is correct using rjstellings code here.
However, if you're using at least Xcode 5.0.1, you should be able to get away with not specifying the bundle name. Additionally, since your ViewController class appears to have the same name as the xib, Xcode is smart enough to let you get away with not needing to specify that either.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
BNRReminderViewController *rvc = [[BNRReminderViewController alloc] init];
[self.window setRootViewController:rvc];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
You don't have to call mainBundle. It might be nil. This code might be solution:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.dashboardVC = [[DashboardViewController alloc] initWithNibName:#"DashboardViewController" bundle:nil];
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:self.dashboardVC];
self.window.rootViewController = nc;
[self.window makeKeyAndVisible];
return YES;
}
Otherwise, did you create app with Storyboard? If you start with Storyboard, you have to remove the line below:

receiver type 'AppDelegate' for instance message does not declare a method with selector ERROR

Can't seem to nail this issue here. Any idea what needs to be changed? I'm using Xcode 4.2.
Error: AppDelegate.m:23:6: error: receiver type 'AppDelegate' for instance message does not declare a method with selector 'setupHUD' [4]
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
LoginViewController *loginVC = [[LoginViewController alloc] init];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:loginVC];
navCon.navigationBarHidden = YES;
self.window.rootViewController = navCon;
[self setupHUD];
[self.window makeKeyAndVisible];
return YES;
}
- (void) setupHUD
{
//setup progress hud
self.HUD = [[MBProgressHUD alloc] initWithFrame:self.window.bounds];
[self.window addSubview:self.HUD];
self.HUD.dimBackground = YES;
self.HUD.minSize = CGSizeMake(150.f, 150.f);
self.HUD.delegate = self;
self.HUD.isCancelButtonAdded = YES;
self.HUD.labelText = #"Loading";
}
Prior to Xcode 4.3, you need to forward declare methods called within the same #implementation block, so make sure to add the declaration of setupHUD to either the class extension (the list of declarations inside AppDelegate.m that starts with #interface AppDelegate ()), or the #interface block in AppDelegate.h.
For example, in AppDelegate.m:
#interface AppDelegate ()
// Other declarations...
- (void)setupHUD;
#end
Or in AppDelegate.h:
#interface AppDelegate : NSObject <UIApplicationDelegate>
// Other declarations
- (void)setupHUD;
#end

Application windows are expected to have a root view controller at the end of application launch error

I keep getting this error, and I cannot figure out why. Everything was working fine, and all of the sudden I got this error. I had not changed the code, and I set the rootViewController in the delegate, so I don't see why I am getting this error. Here is the code from my appDelegate.m file.
#import "WhereAmIAppDelegate.h"
#import "WhereAmIViewController.h"
#implementation WhereAmIAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
WhereAmIViewController *wvc = [[WhereAmIViewController alloc] initWithNibName:#"WhereAmIViewController" bundle:nil];
[[self window]setRootViewController:wvc];
[self.window makeKeyAndVisible];
return YES;
}
I clearly set the rootViewController, so I don't know why this is happening.

Objective-c and Xcode strange behavior

In xcode 4.3.1, target iPad 5.1 simulator
create a single view app
use ARC, don't use Storyboard
in ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
NSObject *anObject;
NSObject *anotherObject;
}
-(void) makeObjects;
#end
in ViewController.m add
-(void) makeObjects{
anObject = [[NSObject alloc] init];
anotherObject = [[NSObject alloc] init];
int a = 1;
}
in AppDelegate.m add a line
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.viewController makeObjects]; // ADD THIS LINE <--------
[self.window makeKeyAndVisible];
return YES;
}
in ViewController.m, set a breakpoint at
anObject = [[NSObject alloc] init];
run
step over breakpoint
anObject = 0x00000000, anotherObject is set!
Are you using the LLDB debugger? Currently it doesn't give you correct values on iVars in the simulator. Switch back to GDB and you'll find the correct values reported. I discovered this behavior here: UIViewController subclass can't assign instance variable.
And yes, I reported a bug. I got a response back from Apple stating it is a known issue.