I’ve just begun Objective-C and am looking to find a way to create an iPhone app that will launch with a Main Menu consisting of maybe around 8 or 9 buttons.
When the buttons are pressed it will link to a Scrolling Text view (containing a good few paragraphs of text) with an accompanying image at the top of the screen, which will act as a “Back” button to return to the Main Menu. I was also looking it to animate/behave as a modalview (where the new view scrolls up from the bottom of the screen, and scrolls back down when dismissed/Back-button pressed).
I have got the Tab Views working within a modal view (which is brought up from pressing a button in the Main Menu) and have worked out how to assign a custom icon to each tab. I’ve also added a custom background for each Tab. Though I’m still having trouble adding scrolling views to each Tab, where I can insert pictures and text programmatically. I would really appreciate any help you could give me with this..
Thanks very much!!
.h
#import <UIKit/UIKit.h>
@interface MasseurViewController : UIViewController {
UITabBarController *tbc;
}
-(IBAction)showHeadTabBar;
-(void)dismissTabBar;
@property (nonatomic, retain) UITabBarController *tbc;
@end
.m
#import "MasseurViewController.h"
@implementation MasseurViewController
@synthesize tbc;
//---Implement all the possible Tab Bar views
-(IBAction)showHeadTabBar{
//---Define Back button
UIImage *backImage = [UIImage imageNamed:@"headBackButton.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, backImage.size.width, backImage.size.height);
[button setImage:backImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(dismissTabBar) forControlEvents:UIControlEventTouchUpInside];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(0.0f, 0.0f, backImage.size.width, backImage.size.height);
[button2 setImage:backImage forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(dismissTabBar) forControlEvents:UIControlEventTouchUpInside];
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(0.0f, 0.0f, backImage.size.width, backImage.size.height);
[button3 setImage:backImage forState:UIControlStateNormal];
[button3 addTarget:self action:@selector(dismissTabBar) forControlEvents:UIControlEventTouchUpInside];
//------------************TABS**************-------------------
//-------------------------------------------------------------
//---------------Declare View Controllers-----------
//---------------------------TAB 1
UIViewController *blueController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
blueController.title = @"Blue";
blueController.tabBarItem.image = [UIImage imageNamed:@"tabBar1.png"];
//---Add tabs & Tab names
[blueController.view addSubview:button];
blueController.view.backgroundColor = [UIColor whiteColor];
blueController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"mainMenuBKG.png"]];
//----TAB 2
UIViewController *redController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
redController.view.backgroundColor = [UIColor grayColor];
redController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"shouldersImage1.png"]];
//----TAB 3
UIViewController *greenController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
greenController.view.backgroundColor = [UIColor greenColor];
//--------------------------------------------------
//---Instantiate tab bars
tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
//---Create array of tabs
tbc.viewControllers = [NSArray arrayWithObjects:blueController, redController, greenController, nil];
//---Select starting tab
tbc.selectedViewController = blueController;
//--------------------------------------------------
//---Add tabs & Tab names
[redController.view addSubview:button2];
redController.title = @"Red";
[greenController.view addSubview:button3];
greenController.title = @"Green";
//---Release Tab views
[blueController release];
[redController release];
[greenController release];
[self presentModalViewController:tbc animated:YES];
}
//---Code to dismiss Tab Bars
- (void)dismissTabBar {
[self dismissModalViewControllerAnimated:YES];
[tbc release];
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Your question is too general to illicit a good answer, but I’ll try to point you in the right direction.
You do not have to create a separate .h/.m/.xib for each button – you probably want that main menu page with all the buttons to be controlled by a single view controller class (.h, .m) and it would probably be convenient to create all the buttons in a single .xib file.
The views you create for each button’s action depends on what you want it to do. If 3 of them just show an image, you could re-use a class called displayImageView, for example.
I suggest you get your app working with a single main view with a single button and action, and then figure out how to expand it to 8 or 9 actions.
And finally, I think you have a lot of reading to do. Here is a good place to start. Good luck.