I have a UINavigationcontrol with UISegmentedcontrol and two options. The two options pushes to different UIViewcontrollers. When the user push the second option the UISegmentControl is still there, but when the user push the first option again the UISegmentControl disappears. What code do I need there?
CoreDataMenuAppDelegate.h:
#import <UIKit/UIKit.h>
@interface CoreDataMenuAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UINavigationController *navigationController;
UINavigationController *navigationController2;
UITabBarController *tabBarController;
IBOutlet UISegmentedControl *myMent;
}
-(IBAction)segmentAction:(id)sender;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController2;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
CoreDataMenuAppDelegate.m:
#import "CoreDataMenuAppDelegate.h"
#import "RootViewController.h"
#import "Step3.h"
#import "Step6.h"
@implementation CoreDataMenuAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize navigationController2;
@synthesize tabBarController;
-(void)viewDidLoad
{
[myMent addTarget:self action:@selector(segmentAction:)
forControlEvents:UIControlEventValueChanged];
myMent.selectedSegmentIndex = 0 ;
}
- (IBAction) segmentAction:(id)sender
UISegmentedControl* segCtl = sender ;
if( [segCtl selectedSegmentIndex] == 0 )
{
[navigationController2 popToRootViewControllerAnimated:NO];
//What to put here?
}
if( [segCtl selectedSegmentIndex] == 1 )
{
NSLog(@"hi this is second segment");
Step6 *step6 = [[[Step6 alloc] initWithNibName:@"Step6" bundle:nil] autorelease];
[self.navigationController2 pushViewController:step6 animated:NO];
step6.navigationItem.titleView = segCtl;
}
}
- (void)dealloc {
[navigationController release];
[navigationController2 release];
[tabBarController release];
[window release];
[super dealloc];
}
I've tried:
Step3 *step3 = [[[Step3 alloc] initWithNibName:@"Step3"
step3.navigationItem.titleView = segCtl;
but with no results.
The UISegmentControl shows when I go to the UIViewController, when I press the second segment, but disappears when I go back to the first segment.
Anyone?
Best regards, xqtr
Okey, when I try to use it, the segmentedcontrol disappears from the beginning. I use:
Step3.h:
#import <UIKit/UIKit.h>
@interface Step3 : UIViewController {
UISegmentedControl * segmentedControl;
}
@property (nonatomic, retain) IBOutlet UISegmentedControl * segmentedControl;
@end
Step3.m:
#import "Step3.h"
@implementation Step3
@synthesize segmentedControl;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationItem.titleView = self.segmentedControl;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
@end
I use exactly the same code in step3.h/m and step6.h/m, but now when I tried your snippet the Segmentedcontrol disappears already in the start view (step3).
Any suggestions? :)