I have a little problem:
I have a view with a view controller and a tabbarcontroller in a main window.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
On this view I have around 10 Labels.
As soon as I connect 1 Label on the Interface-Builder with the UILabel in the controller, I get a SIGBART error.
Here is my code:
#import <UIKit/UIKit.h>
#interface SelfViewController : UIViewController
{
IBOutlet UILabel *id2;
IBOutlet UILabel *username;
IBOutlet UILabel *vorname;
IBOutlet UILabel *nachname;
IBOutlet UILabel *email;
}
#end
What am I doing wrong?
Here is a solution, very basic and simple but very frustrating too:
https://discussions.apple.com/thread/1598422?threadID=1598422
Related
I am trying to convert my iPad app from using a Tab Bar Controller as its Root View to using a Split View Controller for it. My code in my AppDelegate.h is:
#class RootViewiPad;
#class WebViewController2;
#interface AppDelegate : NSObject <UIApplicationDelegate, UISplitViewControllerDelegate> {
UIWindow *window;
UISplitViewController *splitViewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
#end
The .m is:
#import "AppDelegate.h"
#import "WebViewController2.h"
#implementation AppDelegate
#synthesize window;
#synthesize splitViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
I use IB to set all this up, and I Added a SplitViewController in the MainWindow, and connected the AppDelegate Connection for SplitViewController to the SplitViewController I added. Under the Navigation Controller in the SplitViewController I set the root view to RootViewiPad (The TableView that parses a blog and shows the articles), and then set the other View Controller Class and NIB to WebViewController2 which is where I would like the articles to display once they are clicked on. When I run the app, it compiles, and I can see the WebViewController2 that I built in IB, and when I rotate, the left hand side is the TableView I created. However, I can't figure out how to get it to load the URL in the WebViewController2. Everything I have tried either does nothing, or merely pushes it on the Master Side of the controller.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewController2 *detailViewController =
self.webViewController2;
detailViewController.webView.scalesPageToFit = NO;
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
[detailViewController.webView loadHTMLString:entry.articleImage baseURL:[NSURL URLWithString:nil]];
}
}
Any suggestions?
So here is my question.
I am using s subview of my MainViewcontroller to implement a TabBar in the following manner:
#class MainViewController;
#interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
// UITabBarController root controller view
UITabBarController *rootController;
}
// Added
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
// Added root controller
[self.window addSubview:rootController.view];
return YES;
}
I have 4 view controllers and 4 tabs. I have specified in each tab view .m and in the main view controller:
// Autoration of view orientations
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
I get no rotation to any orientation but in my main view controller. I thought I needed to override the main view but my understanding is not sufficient. Please provide me with assistance.
Take a look at this. And at this question here.
i used the code below to make a UITabBarController :
inside AppDelegate.h:
IBOutlet UITabBarController *rootController;
...
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
inside AppDelegate.m
#synthesize rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
Now i need to know how to implement this method inside AppDelegate:
- (void)SwitchToTab:(int)index{
//go to tabview 1 or 2 ...
}
You can do this:
self.rootController.selectedIndex = 2; // or whatever index you like
or this:
self.rootController.selectedViewController = oneOfTheViewControllersInTheTabController;
See the UITabBarController reference page for details.
UIView not shown on my window based template?
I am creating an app for this a was use the window based template and a view controller and for checking drop label but after execution it appears like clean white window.
in delegate header file i do this
#import "First_View.h"
#class First_View;
#property (nonatomic, retain) First_View *viewcontroller;
And in delegate.m
#synthesize viewcontroller=_viewcontroller;
//in implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewcontroller; /*/**main line code here**/*/
[self.window makeKeyAndVisible];
return YES;
}
You can add the ViewController View to the window like that:
[self.window addSubView:self.viewcontroller.view];
And the view Controller should have an outlet if you are creating it using Interface Builder and don't forget to connect it:
#property (nonatomic, retain) IBOutlet First_View *viewcontroller;
Noobie so bear with me.
I've have been following the O'Rielyy Learning iPhone Programming and various threads on here to build my first iPhone App. So far so good, but the final stumbling block at the projects end is getting the App to autorotate (the beta using only uiwebviews was rejected for not auto-rotating)
I have the mail App delegate, which adds a UITabBarController
// myNewsUKDelegate.h
#interface myNewsUKDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
#end
// myNewsUKDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
There is are .h and .m files for tabBarController - I added all the UINavigationControllers in IB, which in turn add a UITableView
See image at http://flatearth.co.uk/nib.png (too noob to post images in questions!)
From my reading I understand that the issue is the UITabBarController I added to the main view needs to be 'subclassed' and have this code added.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
The next view down/in/subclassed (whatever the correct terminology is), which has .h and .m files is the FirstViewController which adds the table view, this has shouldAutorotateToInterfaceOrientation already set.
#interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
UITableView *tableView;
NSArray *userList;
}
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#property (nonatomic, retain) NSArray *userList;
#end
#implementation FirstViewController
#synthesize tableView;
- (void)viewDidLoad {
[super viewDidLoad];
// I tried adding
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// lots of other code ; )
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
So the problem appears to be that when [self.window addSubview:tabBarController.view]; adds the tab bar it doesn't add the shouldAutorotateToInterfaceOrientation returning YES bit.
It appears that I need to add a tabBarController subclass, with the shouldAutorotateToInterfaceOrientation in it. So I read up and tried this, as suggested on the interwebs...
// tabBarController.h
#import <UIKit/UIKit.h>
#interface tabBarController : UITabBarController {
}
#end
// tabBarController.m
#import "tabBarController.h"
#implementation tabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
#end
and adding
#import "tabBarController.h"
to myNewsUKDelegate.m
But that fails with "error: accessing unknown 'view' class method" at the
[self.window addSubview:tabBarController.view];
line in myNewsUKDelegate.m
Further searching hasn't produced anything helpful and my recent Xcode knowledge has now ran dry : ( Any help appreciated.
From my reading I understand that the issue is the UITabBarController I added to the main view needs to be 'subclassed' and have this code added.
No, you don't need to do that. The tab bar controller determines if it supports a specific interface orientation or not by asking all its child controllers if they support this orientation. In your case, these seem to be navigation controllers, which in turn ask their current child controller if it supports the orientation.
In other words, you have to make sure that all your custom view controllers return YES for the desired interface orientation.
You don't need a subclass, you need a Category on UITabBarController. Basically you create a file called UITabBarController + Autoresize.h (and .m)
In the .h:
#import <UIKit/UIKit.h>
#interface UITabBarController (Autoresize)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
#end
in the .m:
#import "UITabBarController + Autoresize.h"
#implementation UITabBarController (Autoresize)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//do custom checks here if you only want to autorotate it in certain views or whatever
}
#end
but as the other poster pointed out, ALL the parent views of the view you wish to rotate must support rotation.