Android
In Android we can implement the options menu to navigate to sub screens as in:
// ON_CREATE_OPTIONS_MENU
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater= getMenuInflater();
inflater.inflate(R.menu.encrypttext_menu, menu);
return true;
}
// HANDLE MENU OPTION CHOICES HERE
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.manage_password:
resetHintsAndErrors();
launchManagePassword(); // child Activity
return true;
default:
return super.onOptionsItemSelected(item);
}
}
iOS
In iOS we can add a UITabBar to the main AppDelegate as in:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UITabBarController *tabBarController= [[UITabBarController alloc]init];
UIViewController *vcMain= [[EncryptSMSViewController alloc]init];
UIViewController *vcPassword= [[PasswordController alloc]init];
NSArray *viewControllers= [NSArray arrayWithObjects:vcMain, vcPassword, nil];
[vcMain release];
[vcPassword release];
[tabBarController setViewControllers:viewControllers];
[[self window] setRootViewController:tabBarController];
[tabBarController release];
[self.window makeKeyAndVisible];
return YES;
}
Then in each sub view we set the UITabBarItem title and image as in:
-(id)init {
self= [super initWithNibName:nil bundle:nil];
if (self) {
UITabBarItem *tbi= [self tabBarItem];
[tbi setTitle:@"New Password"];
UIImage *image= [UIImage imageNamed:@"add.png"];
[tbi setImage:image];
}
return self;
}
The images in each UITabBarItem will display as a silhouette and the images should be 30X30.
You can programatically show a sub screen by retaining the tabBarController as an instance variable and setting the tabBarController selected index as in:
-(void)switchView:(NSInteger) viewInt{
self.tbController.selectedIndex= 1;
}
You may need to declare a delegate to notify the owner of the tabBarController to change the sub screen. So if the owner of the tabBarController is MyAppAppDelegate and if the sub screen requesting the view change is MyAppViewController and if MyAppAppDelegate "owns" MyAppViewController then:
1) Declare the delegate protocol in Protocols.h as in:
@protocol VCDelegate <NSObject>
-(void)switchView:(NSInteger) viewInt;
@end
2) Declare the delegate property in MyAppViewController.h as in:
@property (nonatomic, assign) id <VCDelegate> delegate; // assign delegates, avoid retain cycle, delegate is a weak reference
3) Synthesize the property in MyAppViewController.m as in:
@synthesize delegate;
4) #import "Protocols.h" header in MyAppAppDelegate.m and as in:
#import "Protocols.h"
5) Declare that MyAppAppDelegate implements the protocol in MyAppAppDelegate.h as in:
@interface MyappAppDelegate : NSObject <UIApplicationDelegate, VCDelegate>
6) Implement the protocol in MyAppAppDelegate as in:
-(void)switchView:(NSInteger) viewInt{
self.tbController.selectedIndex= 1;
}
7) Set the delegate in MyAppViewDelegate as in:
[vcMyAppViewController setDelegate:self];
or
vcMyAppViewController.delegate= self;
8) Message the delegate in MyAppViewController as in:
-(IBAction)showAnotherView: (id)sender{
[delegate switchView:1];
}