MySecondViewController won't display correctly - objective-c

I have programmatically created a second view controller (MySecondViewController) which was all done and hooked up without using the visual object editor.
My problem is that when I run the app, only the original view controller (HelloWorldViewController) comes up; the second view controller does not show up. When I click on the view for HelloWorldViewController, nothing comes up.
Can you tell me what's wrong?
windowBasedAppAppDelegate.h
#import <UIKit/UIKit.h>
//-- Add a forward reference to the HelloWorldViewController class --
#class HelloWorldViewController;
#interface windowBasedAppAppDelegate : NSObject <UIApplicationDelegate> {
//-- create an instance of the view controller--
HelloWorldViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
//--Expose the view controller as a property--
#property (nonatomic, retain) IBOutlet HelloWorldViewController *viewController;
#end
windowBasedAppAppDelegate.m
#import "windowBasedAppAppDelegate.h"
#import "HelloWorldViewController.h"
#import "MySecondViewController.h"
#implementation windowBasedAppAppDelegate
#synthesize window;
#synthesize viewController;
//-- a second view controller object--
MySecondViewController *mySecondViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//-- add the new view to the current window--
//-- instantiate the second view controller --
mySecondViewController = [[MySecondViewController alloc]
initWithNibName:nil
bundle:nil];
// -- add the view from the second controller --
//[window addSubview:mySecondViewController.view];
[window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[MySecondViewController release];
[viewController release];
[window release];
[super dealloc];
}
#end
MySecondViewController.h
#import <UIKit/UIKit.h>
#interface MySecondViewController : UIViewController {
//-- create two outlets, label and button --
UILabel *label;
UIButton *button;
}
//-- expose the outlets as properties --
#property (nonatomic, retain) UILabel *label;
#property (nonatomic, retain) UIButton *button;
// -- declaring the IBAction ---
- (IBAction) buttonClicked: (id)sender;
#end
MySecondViewController.h
#import "MySecondViewController.h"
#implementation MySecondViewController
#synthesize label, button;
- (IBAction) buttonClicked: (id)sender {
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:#"Action Invoked!" message:#"Button clicked" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
HelloWorldViewController.h
#import <UIKit/UIKit.h>
#interface HelloWorldViewController : UIViewController {
}
#end
HelloWorldViewController.m
import "HelloWorldViewController.h"
#implementation HelloWorldViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
Added code from MySecondViewController.m
//-- add the views to the view window --
[self.view addSubview:label];
[self.view addSubview:button];
[view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
self.view = view;
[super viewDidLoad];

Since the view is being initialized and that it has a proper frame, the problem could be this sequence of code,
[window addSubview:mySecondViewController.view];
[window addSubview:viewController.view];
As the viewController's view will have the same frame, it will be added over mySecondViewController's view. So you will have to remove the second line for the view to show up.

You never actually push the new view controller onto the screen.
mySecondViewController = [[MySecondViewController alloc]
initWithNibName:nil
bundle:nil];
// -- add the view from the second controller --
//[window addSubview:mySecondViewController.view];
[window addSubview:viewController.view];
You add viewController.view, (which should be undefined...), but not mySecondViewController.view.
Also, programHasFinishedLaunching may not be the best possible place to push it. If I were you, I'd put a button on the front page that pushes the new view in, it's easier that way.

Related

how to give action to UIButtoun Outlet from another UIViewController

I have two UIViewController class with names : (RootViewController & SecondViewController).
I have one UIButton Outlet in my SecondViewController.now I want give action method to my UIButton in RootViewController.but I don't know about it.
please guide me and tell me how to get my UIButton in another View and give action method on it in another View....
I'm not sure why you are doing this, it doesn't look good.
Anyway, here's the way.
SecondViewController.h
#interface SecondViewcontroller:UIViewController
#property (nonatomic, weak) IBOutlet UIButton *theButton;
#end
RootViewController.m
SecondViewContoller * sv = [[SecondViewController alloc] init];
[sv.theButton addTarget:self action:#selector(buttonHandler:) forControlEvents:UIControlEventTouchUpInside];
You have to removeTarget when you've done with the button.
Why don't you use delegate or block callback?
ADDED
delegate
SecondViewController.h
#protocol SecondViewControllerDelegate <NSObject>
- (void)theButtonPressed;
#end
#interface SecondViewController : UIViewController
#property (nonatomic, strong) id<SecondViewControllerDelegate>delegate;
#end
SecondViewController.m
#interface SecondViewController ()
{
UIButton *theButton;
}
#end
#implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[theButton addTarget:self.delegate action:#selector(theButtonPressed) forControlEvents:UIControlEventTouchUpInside];
}
#end
RootViewcontroller.h
#interface RootViewController : UIViewController <SecondViewControllerDelegate>
#end
RootViewController.m
SecondViewController *sv = [[SecondViewController alloc] init];
[sv setDelegate:self];
and
- (void)theButtonPressed
{
}
block
SecondViewController.h
typedef void(^TheButtonTouched)(void);
#interface SecondViewController : UIViewController
- (void)addButtonEvent:(TheButtonTouched)event;
#end
SecondViewController.m
#interface SecondViewController ()
{
UIButton *theButton;
TheButtonTouched buttonBlock;
}
#end
#implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// button alloc init here and..
[theButton addTarget:self action:#selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonEvent:(UIButton *)sender
{
if(buttonBlock)
{
buttonBlock();
}
}
- (void)addButtonEvent:(TheButtonTouched)event
{
buttonBlock = event;
}
#end
RootViewController.m
SecondViewController *sv = [[SecondViewController alloc] init];
[sv addButtonEvent:^{
// ADD SOMTHING HERE
}];
You need to create the button's iboutlet property.
Than using object of secondclass.button name you can assign selector.
[classobjectname..btnname addTarget:objectname.class action:#selector(objectname.methodname:);
Just Create RootViewController 's Object and passed into target parameter.
e.g.
[btnShow addTarget:self.rootCtrlObj action:#selector(viewPhoto_click:)
forControlEvents:UIControlEventTouchUpInside];
where rootCtrlObj is #property inside SecondViewController.h file
and when you push this controller in RootViewController you have to pass reference of RootViewController .
For Example,
secVCObj.rootCtrlObj = self;
[self.navigationController pushViewController:secVCObj animated:YES];
as i said custom delegate methods will work perfect for these cases,
in SecondViewController.h file define a custom delegate method like below
#import <UIKit/UIKit.h>
#import "ViewController.h"
#protocol SecondControllerDelegate<NSObject>
- (void)someActionToPerformInRootController;
#end
#interface SecondViewController : UIViewController
#property (nonatomic, assign) id<SecondControllerDelegate>delegate; //declare a custom delegate
#end
in SecondViewController.m file lets take an action of some button
- (IBAction)myButtonActionMethod:(id)sender
{
if([self.delegate respondsToSelector:#selector(someActionToPerformInRootController)])
{
[self.delegate someActionToPerformInRootController]; //this will call the delegate method in first view conroller( root view controller) //do what ever u want t do in the action method of rootviewcontroller
}
}
in RootViewController.h file
#import "SecondViewController.h"
#interface RootViewController : UIViewController < SecondControllerDelegate> //confirmas to delegate
in RootViewController.m while presenting the SecondViewController set the delegate to self
- (IBAction)showAction:(id)sender
{
SecondViewController *secondController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
secondController.delegate = self; //call back to this controller
[self presentViewController:secondController animated:YES completion:nil];
}
//this method called from the secondViewcontroller
- (void) someActionToPerformInRootController
{
NSLog(#"perform action in root view controller");
}

Xcode: How do I change UIPageControl value with swipe gesture?

I have a quick question I was hoping you guys could help me answer. Right now I have a UIPageControl in a storyboard which changes an image depending on what dot you are on, however, as of now you have to press on the dot to change through the dots/images, how can I change through the images/dots by swiping?
Here is my code for my .h
#import <UIKit/UIKit.h>
#interface PageViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *dssview;
- (IBAction)changephoto:(UIPageControl *)sender;
#end
Here is my code for my .m
#import "PageViewController.h"
#interface PageViewController ()
#end
#implementation PageViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)changephoto:(UIPageControl *)sender {
_dssview.image = [UIImage imageNamed:
[NSString stringWithFormat:#"%d.jpg",sender.currentPage+1]];
}
#end
Any help would be greatly appreciated.
Thanks
You can add UISwipeGestureRecognizer to your view and in the selector method of UISwipeGestureRecognizer based on the direction update the UIPageControl object, either increment the current page or decrement.
You can refer the below code.
Adding swipe gesture to the view controller
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipe:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
Swipe gesture selector
- (void)swipe:(UISwipeGestureRecognizer *)swipeRecogniser
{
if ([swipeRecogniser direction] == UISwipeGestureRecognizerDirectionLeft)
{
self.pageControl.currentPage -=1;
}
else if ([swipeRecogniser direction] == UISwipeGestureRecognizerDirectionRight)
{
self.pageControl.currentPage +=1;
}
_dssview.image = [UIImage imageNamed:
[NSString stringWithFormat:#"%d.jpg",self.pageControl.currentPage]];
}
Add an outlet to the UIPageControl in the .h file
#interface PageViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *dssview;
#property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
- (IBAction)changephoto:(UIPageControl *)sender;
#end

property implementation must have its declaration in interface error

"property implementation must have its declaration in interface" error
I have this error coming up and I am new to xcode so I am unsure what to do.
I had lots of code in a class, then i moved it to a different class and now I have numerous errors. Which dont make sense, as everything looks as it should.
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize MenuScreenButton;
#synthesize HowToPlayButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (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)HowToPlayButtonPressed:(id)sender
{
HowToPlayViewController *HowToPlayView=[[HowToPlayViewController alloc]initWithNibName:nil bundle:nil];
HowToPlayView.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:HowToPlayView animated:YES completion:NULL];
}
-(IBAction)MenuScreenButtonPressed:(id)sender
{
MenuScreen *MenuScreenView=[[MenuScreen alloc]initWithNibName:nil bundle:nil];
MenuScreenView.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:MenuScreenView animated:YES completion:NULL];
}
#end
Below is the .h file:
#import <UIKit/UIKit.h>
#import "HowToPlayViewController.h"
#import "MenuScreen.h"
#interface ViewController : UIViewController
{
IBOutlet UIButton *HowToPlayButton;
IBOutlet UIButton *MenuScreenButton;
}
#property(retain,nonatomic) IBOutlet UIButton *MenuScreenButton;
#property(retain,nonatomic) IBOutlet UIButton *HowToPlayButton;
-(IBAction)HowToPlayButtonPressed:(id)sender;
-(IBAction)MenuScreenButtonPressed:(id)sender;
#end

How to send array to subview and then print into label?

Working over storyboard.
I've created View Controller (storyboard) and then in middle of content added subview from xib file.
I want to add xib (UIView) like as subview into ViewController and send object with data and print that data into label but I don't know how.
Here is my code.
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
UIView *subView;
}
#property (strong, nonatomic) IBOutlet UIView *subView; //connected over IB
#end
ViewController.m
#import "OfferViewController.h"
#import "OfferLocation.h"
#interface OfferViewController ()
#end
#implementation OfferViewController
#synthesize subView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
OfferLocation *location = [[OfferLocation alloc] initWithFrame:CGRectZero];
[self.subView addSubview:location];
}
...
#end
and here is subview:
OfferLocation.h
#import <UIKit/UIKit.h>
#interface OfferLocation : UIView{
UIView *view;
UILabel *locationLabel;// here is that label taht I want to print into
}
#property (nonatomic, retain) IBOutlet UIView *view;// connected over IB
#property (nonatomic, retain) IBOutlet UILabel *locationLabel;
#end
OfferLocation.m
#import "OfferLocation.h"
#implementation OfferLocation
#synthesize view, locationLabel;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
locationLabel.text = #"some text"; //this is not working
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:#"OfferLocation" owner:self options:nil];
UIView *tempView = [subviewArray objectAtIndex:0];
[self addSubview:tempView];
}
return self;
}
subView never seems to be initialized and loaded to the view or presented. Therefore you cannot see it.
Try calling:
self.view = self.subView // or subView; // or [self.view addSubview:self.subView // or subview];
or something similiar
Then declare a UILabel and initialize it with whatever text you want and add it to subview:
UILabel *label = [[UILabel alloc] initWithString:#"StackOverflow rocks!"];
[self.subView addSubview:label];
// or [self.view addSubview:label];
Differing on how you set subView.
What is this data you want to set on label's text? If it is a data type use the specifiers in the string.
%i // for int
%# // for string or object adress
%c // for char
%f // for float
etc...

Orientation Problem with more Views and Controller (iPad)

Im writing an App for iPad using Orientation.
The App-Delegate.h has a window, an UIViewController, an UINavigationController and an UITabbarController:
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet LoginRVC *loginRVC;
#property (nonatomic, retain) IBOutlet ChooseCameraRVC *chooseCameraRVC;
#property (nonatomic, retain) IBOutlet UITabBarController *hauptRVC;
Every Controller uses the "shouldAutorotateToInterfaceOrientation"-method to autorotate itself.
i change the views using:
[UIView beginAnimations:nil context:NULL];
and then
[loginRVC.view removeFromSuperview];
[_window addSubview:chooseCameraRVC.view];
and the other way around too, ofc.
So my problem is, when i am in the second view (chooseCameraRVC) and switch the orientation, then go back to my first view, its not rotated. It do autorotate but after the animation is completed.
I tried many things like calling "shouldAutorotateToInterfaceOrientation"-method of all views, not removing the views from window ... but no success til now.
Is this maybe a "feature" of the simulator? (i hope not).
Pls help me.
Sharky
Ok. I prepared my source code to be presented here.
Note: I didn't copy the methods which only has [super ...] within or are completely commented out.
At first the AppDelegate.h:
#import <UIKit/UIKit.h>
#import "ChooseCameraRVC.h"
#import "LoginRVC.h"
#interface NetCoWatchAppDelegate : NSObject <UIApplicationDelegate>
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet LoginRVC *loginRVC;
#property (nonatomic, retain) IBOutlet ChooseCameraRVC *chooseCameraRVC;
-(void)changeView:(id)sender:(BOOL)direction;
#end
AppDelegate.m:
#import "NetCoWatchAppDelegate.h"
#import "LoginRVC.h"
#import "ChooseCameraRVC.h"
#import "ChooseCameraVC.h"
#implementation NetCoWatchAppDelegate
#synthesize window = _window;
#synthesize loginRVC, chooseCameraRVC;
-(void)changeView:(id)sender:(BOOL)direction{
//configure animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
if(sender == loginRVC){ //sender is LoginView
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_window cache:YES];
[loginRVC.view removeFromSuperview];
[_window addSubview:chooseCameraRVC.view];
}else if(sender == chooseCameraRVC){
[chooseCameraRVC.view removeFromSuperview];
if(!direction){ //FlipFromRight = YES, ...left = NO
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_window cache:YES];
[_window addSubview:loginRVC.view];
}
}else if([sender class] == [ChooseCameraVC class]){
[chooseCameraRVC.view removeFromSuperview];
if(!direction){ //Camera gewählt //FlipFromRight = YES, ...left = NO
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_window cache:YES];
[_window addSubview:loginRVC.view];
}
}else { //default solution
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Bad Value" message:[[sender class] description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
[av release];
}
[UIView commitAnimations]; //start animation
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[_window release];
[loginRVC release];
[chooseCameraRVC release];
[super dealloc];
}
#end
The LoginRVC.h:
#import <UIKit/UIKit.h>
#interface LoginRVC : UIViewController <UITextFieldDelegate>{
NSMutableArray *usernameArray;
NSMutableArray *passwordArray;
}
#property (nonatomic, retain) IBOutlet UITextField *usernameTF;
#property (nonatomic, retain) IBOutlet UITextField *passwordTF;
#property (nonatomic, retain) IBOutlet UIButton *loginBn;
#property (nonatomic, retain) IBOutlet UISwitch *saveUsernameSwitch;
-(IBAction)tryLogin:(id)sender;
-(IBAction)closeKeyboard:(id)sender;
#end
The LoginRVC.m:
#import "LoginRVC.h"
#import "NetCoWatchAppDelegate.h"
#implementation LoginRVC
#synthesize usernameTF, passwordTF, loginBn, saveUsernameSwitch;
-(IBAction)tryLogin:(id)sender{
//login successful if the textfields are euqal with an existing account
#warning Access the data base and search for the account.
bool accountFound = NO;
for (int i=0; i<usernameArray.count; i++) {
if([[usernameArray objectAtIndex:i] isEqualToString:usernameTF.text]
&& [[passwordArray objectAtIndex:i] isEqualToString:passwordTF.text]){
accountFound = YES;
break;
}
}
if(accountFound)
{ //login successful - now change the values and then the view
if(![saveUsernameSwitch isOn])
usernameTF.text = #"";
passwordTF.text = #"";
NetCoWatchAppDelegate *main = (NetCoWatchAppDelegate*)[[UIApplication sharedApplication] delegate];
[main changeView:self:YES];
}else{ //login failt - show a popup window for the user
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Login fehlgeschlagen" message:#"Username oder Passwort falsch!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
[av release];
}
}
-(IBAction)closeKeyboard:(id)sender{
if([passwordTF isFirstResponder])
[passwordTF resignFirstResponder];
else
[usernameTF resignFirstResponder];
}
// this helps dismiss the keyboard then the "done" button is clicked
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(textField == usernameTF){ //move to password textfield
[textField resignFirstResponder];
[passwordTF becomeFirstResponder];
}else if(textField == passwordTF){ //textField == passwordTF -> try to login
[textField resignFirstResponder];
[self tryLogin:self];
}
return YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
#warning Define right keyboard type.
usernameArray = [[NSMutableArray alloc] initWithObjects:#"dkoehn", #"bmazanek", #"sbehne", #"mballhausen", #"efiedler", #"bbraasch", #"azuber", #"tstolt", nil];
passwordArray = [[NSMutableArray alloc] initWithObjects:#"test1",#"test2",#"test3",#"test4",#"test5",#"test6",#"test7",#"test8", nil];
// usernameTF.keyboardType = UIKeyboardTypeEmailAddress;
[usernameTF becomeFirstResponder]; //get first focus when the app stars
//set return key on the keyboard and the delegate for an action
usernameTF.returnKeyType = UIReturnKeyNext; // type of the return key
passwordTF.returnKeyType = UIReturnKeyGo;
//set delegate to connect with a method "-(BOOL)textFieldShouldReturn:(UITextField *)textField"
usernameTF.delegate = self;
passwordTF.delegate = self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#end
The ChooseCameraRVC.h:
#import <UIKit/UIKit.h>
#interface ChooseCameraRVC : UINavigationController <UINavigationControllerDelegate>
#property (nonatomic, retain) IBOutlet UIBarButtonItem *zurueckBN;
-(IBAction)exitToLoginView:(id)sender;
#end
The ChooseCameraRVC.m:
#import "ChooseCameraRVC.h"
#import "NetCoWatchAppDelegate.h"
#import "ChooseCameraCell.h"
#implementation ChooseCameraRVC
#synthesize zurueckBN;
-(IBAction)exitToLoginView:(id)sender{
#warning Eventually logout the User.
//change the view
[((NetCoWatchAppDelegate*)[[UIApplication sharedApplication] delegate]) changeView:self:NO];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#end
ChooseCameraVC.h:
#import <UIKit/UIKit.h>
#interface ChooseCameraVC : UITableViewController <UITableViewDelegate>
#end
and the ChooseCameraVC.m:
#import "ChooseCameraVC.h"
#import "ChooseCameraCell.h"
#import "NetCoWatchAppDelegate.h"
#implementation ChooseCameraVC
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Customize the number of sections if grouped.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
#warning Get count of cameras out of the data base.
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = #"Camera";
return cell;
}
#end
I hope u can find the problem.
Greetings. $h#rky
now i found my mistake. as u can see i have the views as variables in the app delegate. so if the second view changes the orientation, the other ones didn't know a thing about it. if the view now changes the "new" one recognizes the orientation change AFTER the animation, so while the animation is running, the "new" view has the wrong orientation.
So if u want to switch a view, just create a new one because it gets initialized with the right orientation.
kind regards
$h#rky
For support all orientations your viewcontroller should implement shouldAutorotateToInterfaceOrientation like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Every viewcontroller should implement this method for support required orientations.
Check also Supported interface orientations item in .plist file. Maybe you have wrong parameters.
Try this in your secondviewcontroller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIViewController *controller = [self.navigationController.viewControllers objectAtIndex:0];
[controller shouldAutorotateToInterfaceOrientation:interfaceOrientation];
return YES;
}
Hope it works..!!:)