on top tabbar controller or segmented - iphone

so guys, i've been wondering, currently i'm in the middle of learning on developing apps. i saw a CNBC apps at ipad that looks like the image here : (sorry, new user cant directly post image D:)
http://images.thoughtsmedia.com/resizer/thumbs/size/600/at/auto/1291813093.usr105634.jpg
my question is, what are those 2 bars on top of the app??(the one with markets, and indexes)
is it a tabbar controller?? if it is how do we put it on top of the app instead of at the bottom like it normally is, and how do we have another tabbar inside a tabbar???
i appreciate your helps, and sorry for my bad english :3

okay, i have found the solution to this, by far i've tried both customized tabbar and segmented controller, but i found both of them risky and too complicated
so i do a little experiment with simple button
here's the main idea
first, i set up a toolbar, and give it a background
-in viewController.h
//adding my viewcontrollers
#class notLoggedHome;
#class LoggedInHome;
#class NABViewController;
//defining all the objects
#properties (nonatomic, strong) UIToolBar *mainToolBar;
#properties (nonatomic, strong) UIButton *toolBarBut1, *toolBarBut2, *toolBarBut3;
#properties (nonatomic, strong) UIImageView *logoImage;
#property (nonatomic, strong) notLoggedHome *viewNotLoggedHome;
#property (nonatomic, strong) LoggedInHome *viewLoggedInHome;
#property (nonatomic, strong) NABViewController *viewNAB;
#properties NSInteger lastTag;
-in viewController.m
#synthesize mainToolBar, toolBarBut1, toolBarBut2, toolBarBut3;
#synthesize logoImage, lastTag;
#synthesize viewNotLoggedHome, viewLoggedInHome, viewNAB;
-(void)viewDidLoad
{
lastTag = 100;
self.view.backgroundColor = [UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1];
//---
//---fakeTabBar set up===
viewNotLoggedHome = [[notLoggedHome alloc]init];
viewLoggedInHome = [[LoggedInHome alloc]init];
viewNAB = [[NABViewController alloc]init];
//creating the fakeTabBar
mainToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];
[mainToolBar setBackgroundImage:[UIImage imageNamed:#"menu_bar.jpg"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
//defining images
imgHome = [UIImage imageNamed:#"menu_home.png"];
imgHomeS = [UIImage imageNamed:#"menu_home_s.png"];
imgLogo = [UIImage imageNamed:#"menu_bar_logo_ep.png"];
UIImageView *logoImage = [[UIImageView alloc]initWithImage:imgLogo];
logoImage.frame = CGRectMake(0, 0, imgLogo.size.width, imgLogo.size.height);
//--button setting====
toolBarBut1 = [UIButton buttonWithType:UIButtonTypeInfoLight];
[toolBarBut1 setFrame:CGRectMake(imgLogo.size.width, 1, imgHome.size.width, imgHome.size.height)];
toolBarBut1.tag = 0;
toolBarBut1.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
[toolBarBut1 setImage:imgHome forState:UIControlStateNormal];
[toolBarBut1 setImage:imgHomeS forState:UIControlStateSelected];
[toolBarBut1 addTarget:self action:#selector(barPressed:) forControlEvents:UIControlEventTouchUpInside];
//do the same with the other 2 button
//---------------------
[mainToolBar addSubview:logoImage];
[mainToolBar addSubview:toolBarBut1];
//do the same with the other 2 button
[self.view addSubview:mainToolBar];
[super viewDidLoad];
}
-(void)barPressed:(id)sender
{
UIButton *button = (UIButton *)sender;
if(button.tag == 0 && button.tag != lastTag)
{
[viewNAB removeFromParentViewController];
[viewNotLoggedHome removeFromParentViewController];
[self.view addSubview:viewLoggedInHome.view];
button.selected = YES;
}
if(button.tag == 1 && button.tag != lastTag)
{
[viewNAB removeFromParentViewController];
[viewLoggedInHome removeFromParentViewController];
[self.view addSubview:viewNotLoggedHome.view];
button.selected = YES;
}
if(button.tag == 2 && button.tag != lastTag)
{
[viewLoggedInHome removeFromParentViewController];
[viewNotLoggedHome removeFromParentViewController];
[self.view addSubview:viewLoggedInHome.view];
button.selected = YES;
}
lastTag = button.tag;
}
so the main idea is creating a fake tabbar by using toolbar, assigning UIButton(s) to the toolbar as the fake tabbaritem, and giving mechanism to each button that later will switch your viewcontrollers (you have to alloc the viewcontrollers first at implementation file)
this works well for me, just dont forget to set the view controllers frame Y point +(toolbar Height) because otherwise it will cover the toolbar later
:)

Related

camera overlay picture

edit 3
Good news and bad news. The good news is that in the Connections Inspector by disconnecting the overlay UIToolbar and connecting the UIImageview, I see theKing, but then -- the bad news -- I do not see the UIToolbar, which I also need. So the question now is, how can the user get back to the calling VC when s/he is finished here? How can both the toolbar and the image be part of the the overlay, or can the "go back button" toolbar be on the non-overlay view, or something? Or how can I make both the toolbar and the image show on the OverlayViewController?
edit 3
edit 2
setupImagePicker in OverlayViewController.m.
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
self.imagePickerController.showsCameraControls = NO;
if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 10.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 10.0);
self.view.frame = newFrame;
[self.imagePickerController.cameraOverlayView addSubview:self.view];
}
}
}
edit 2
edit 1
This is the PhotoPicker sample code link.
edit 1
edit 0
Has anyone tried this on an iPhone instead of an iPad? I do not have an iPhone, but I was reading Matt Neuburg's book today where he says UIImagePicker works differently on the 2 devices.
edit 0
I cannot see the image I am attempting to overlay across the camera view in UIImagePicker. No matter how I add the IBOutlet, as a property or not, the image does not show, but the overlayed toolbar shows fine. Why?
OverlayViewController.h with theKing IBOutlet added to Apple's sample code and then commented out for now.
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h>
#protocol OverlayViewControllerDelegate;
#interface OverlayViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
// IBOutlet UIImageView* theKing; ******** temporarily commented out
id <OverlayViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <OverlayViewControllerDelegate> delegate;
#property (nonatomic, retain) UIImagePickerController *imagePickerController;
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType;
#end
#protocol OverlayViewControllerDelegate
- (void)didTakePicture:(UIImage *)picture;
- (void)didFinishWithCamera;
#end
OverlayViewController.m with the property for theKing IBOutlet added to Apple's sample code.
#import "OverlayViewController.h"
enum
{
kOneShot, // user wants to take a delayed single shot
kRepeatingShot // user wants to take repeating shots
};
#interface OverlayViewController ( )
#property (assign) SystemSoundID tickSound;
#property (nonatomic, retain) IBOutlet UIImageView* theKing; // added *********
#property (nonatomic, retain) IBOutlet UIBarButtonItem *takePictureButton;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *startStopButton;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *timedButton;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelButton;
#property (nonatomic, retain) NSTimer *tickTimer;
#property (nonatomic, retain) NSTimer *cameraTimer;
I cannot see the image theKing when I execute the code on an iPhone. Below is a view of the nib I have added showing some of the connections made. No errors are thrown, but I cannot see the image, only the UIToolbar already added.
Update
I've updated it now and tried to replicate what you've done in your question. I've included full source of .h/.m and theKing#2x.png. Create a new project and paste the source into the files and add theKing#2x.png. Everything is done programmatically - you don't need to set anything up in interface builder other than embedding your view in a navigation controller.
Here is theKing#2x.png - http://i.imgur.com/0DrM7si.png
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// assign action to button
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(0, 0, 200, 60);
myButton.center = self.view.center;
[myButton addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[myButton setTitle:#"Image Picker" forState:UIControlStateNormal];
[self.view addSubview:myButton];
}
- (void)buttonPress:(id)sender {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// alert the user that the camera can't be accessed
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:#"No Camera" message:#"Unable to access the camera!" delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[noCameraAlert show];
} else {
// prepare imagePicker view
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
imagePicker.showsCameraControls = NO;
// create view for overlay
CGRect overlayRect = CGRectMake(0, 0, imagePicker.view.frame.size.width, imagePicker.view.frame.size.height);
UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect];
// prepare the image to overlay
UIImageView *overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"theKing"]];
overlayImage.center = overlayView.center;
overlayImage.alpha = 0.5;
// prepare toolbar for overlay
UIToolbar *overlayToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 600, overlayView.frame.size.width, 40)];
overlayToolbar.center = CGPointMake(overlayView.center.x, overlayView.frame.size.height - 20);
overlayToolbar.barStyle = UIBarStyleBlack;
UIBarButtonItem *takePictureButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:#selector(takePictureButtonPressed:)];
UIBarButtonItem *flexibleBarSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
flexibleBarSpace.width = 1000;
UIBarButtonItem *startStopButton = [[UIBarButtonItem alloc] initWithTitle:#"Snap" style:UIBarButtonItemStyleBordered target:self action:#selector(startStopButtonPressed:)];
UIBarButtonItem *timedButton = [[UIBarButtonItem alloc]initWithTitle:#"Timed" style:UIBarButtonItemStyleBordered target:self action: #selector(timedButtonPressed:)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action: #selector(cancelButtonPressed:)];
overlayToolbar.items = [NSArray arrayWithObjects:takePictureButton, flexibleBarSpace, startStopButton, timedButton, cancelButton, nil];
[overlayView addSubview:overlayImage];
[overlayView addSubview:overlayToolbar];
// add the image as the overlay
[imagePicker setCameraOverlayView:overlayView];
// display imagePicker
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
}
}
#pragma mark - UIBarButton Selectors
- (void)takePictureButtonPressed:(id)sender {
NSLog(#"takePictureButtonPressed...");
// TODO: take picture!
}
- (void)startStopButtonPressed:(id)sender {
NSLog(#"startStopButtonPressed...");
// TODO: make this do something
}
- (void)timedButtonPressed:(id)sender {
NSLog(#"timedButtonPressed...");
// TODO: implement timer before calling takePictureButtonPressed
}
- (void)cancelButtonPressed:(id)sender {
NSLog(#"cancelButtonPressed");
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - UIImagePickerController Delegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo {
// determine if the user selected or took a new photo
UIImage *selectedImage;
if ([editingInfo objectForKey:UIImagePickerControllerOriginalImage]) selectedImage = (UIImage *)[editingInfo objectForKey:UIImagePickerControllerOriginalImage];
else if ([editingInfo objectForKey:UIImagePickerControllerEditedImage]) selectedImage = (UIImage *)[editingInfo objectForKey:UIImagePickerControllerEditedImage];
// TODO: Do something with selectedImage (put it in a UIImageView
// dismiss the imagePicker
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Screenshot
This is what it looks like when I run it.
Does this satisfy your app requirements?
One answer I have found is to put the image on a huge button which has as an action Done:. I'll have to figure out a way to tell my user to do it, but at least this will dismiss the image view and finish my setup mode. I would really like a cleaner alternative, so please add answers if you have them. Thanks to all who have considered my question.

Simple Custom UIView Class Broken

I have made a simple subclass of UIView which has a few subviews but its breaking for a reason I can't see.
In my storyboard view controller I have added a UIView and made it the shape I want it, and added my custom class to it. The contents of my subclass is below:
#implementation PersonDetailCell
#synthesize button, requiredMarker, textField;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)layoutSubviews
{
[self setBackgroundColor:[UIColor colorWithRed:87.0f/255.0f green:153.0f/255.0f blue:191.0f/255.0f alpha:1.0f]];
textField = [[DetailTextField alloc] initWithFrame:CGRectMake(10, 0, self.frame.size.width -20, self.frame.size.height)];
[textField setFont:[UIFont fontWithName:#"Helvetica" size:14.0f]];
[textField setTextColor:[UIColor whiteColor]];
[textField setHidden:YES];
[self addSubview:textField];
button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setHidden:YES];
[self addSubview:button];
requiredMarker = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 4, 22)];
[requiredMarker setBackgroundColor:[UIColor redColor]];
[requiredMarker setHidden:YES];
[self addSubview:requiredMarker];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
Then in my view controller code I have imported my subclass and hooked up an IBOutlet of it to my view in my storyboard. In my viewDidLoad of my view controller I also try setting background colour of this view but nothing happens.
All of my code runs without crashing, but my issues:
I can't set the background colour from my view controller, (or any other properties for that matter).
When I run the app, the height is more than that I set in my storyboard (width is fine), but I change the height of the view nowhere.
Any ideas? Am i using the wrong approach somehow?
Thanks.
If it is a table cell, then the class should be extending UITableViewCell. Buttons and textfields can be added on the storyboard - then you can use struts and springs (Size Inspector pane) to ensure the view resizes properly. I don't think layoutSubviews should be used for adding new UI elements (maybe for resizing if you need to do it manually).
Here is some working code:
#interface ChildView()
#property (strong, nonatomic) UITextField *textField;
#property (strong, nonatomic) UIButton *button;
#property (strong, nonatomic) UIImageView *requiredMarker;
#end
#implementation ChildView
#synthesize textField= _textField;
#synthesize button = _button;
#synthesize requiredMarker = _requiredMarker;
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self setBackgroundColor:[UIColor colorWithRed:87.0f/255.0f green:153.0f/255.0f blue:191.0f/255.0f alpha:1.0f]];
self.textField = [[UITextField alloc] init];
[self.textField setFont:[UIFont fontWithName:#"Helvetica" size:14.0f]];
[self.textField setTextColor:[UIColor whiteColor]];
self.textField.text = #"Test text";
[self addSubview:self.textField];
self.button = [[UIButton alloc] init];
self.button.backgroundColor = [UIColor greenColor];
[self addSubview:self.button];
self.requiredMarker = [[UIImageView alloc] init];
[self.requiredMarker setBackgroundColor:[UIColor redColor]];
[self addSubview:self.requiredMarker];
}
return self;
}
-(void)layoutSubviews
{
CGSize hostSize = self.frame.size;
float length = 22;
self.textField.frame = CGRectMake(10, length, hostSize.width, hostSize.height-length);
self.button.frame = CGRectMake(0, 0, hostSize.width, length);
self.requiredMarker.frame = CGRectMake(0, 0, 4, length);
}
#end

1 UIViewController and 2 switching UIViews programmatically

I am bit stack with creating two UIViews which are switchable (each UIView has some of subviews). Since I do not IB, I wanna do that programmatically.
I have tried adding my subviews to my first UIView, then the same with second one and then switching to view like this.
if ([self.setView superview]) {
[self.setView removeFromSuperview];
[self.view addSubview:contentView];
self.navigationItem.title = #"BaseLine";
} else {
[self.contentView removeFromSuperview];
self.view = setView;
self.navigationItem.title = #"Settings";
}
but only thing which works correctly was "title" and nothing appeared on the UIViews. The UIView seems to be OK because when I use
self.view = contentView;
or
self.view = setView;
both showing subviews correctly.
Pls someone kick me to the right direction about this.
tnx
EDIT:
Also pointing the solution, perhaps something wrong with my initialization in the loadView
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
contentView = [[UIView alloc] initWithFrame:screenRect];
setView = [[UIView alloc] initWithFrame:screenRect];
self.view = contentView;
I tried to add it first [self. view add..] but the app crashed, so I used this
EDIT2
the root controller is UITableViewController..it is in navigation view and after choosing a cell this UIVieController (percView) with two UIVies is allocated
ShakeControl *percView = [[ShakeControl alloc] init];
[self.navigationController pushViewController:percView animated:YES];
[percView release];
EDIT3
switch is done by button, but it is fine done because I used that many times and it worked
Here is an example of a view controller that does what you want (I think). It is very basic, just switching between two views with different color backgrounds. But, you could further customize those subviews in the loadView method to display whatever you need.
The interface file:
#interface SwapViewController : UIViewController {
UIView *firstView;
UIView *secondView;
BOOL displayingFirstView;
UIButton *swapButton;
}
#property (nonatomic, retain) UIView *firstView;
#property (nonatomic, retain) UIView *secondView;
#property (nonatomic, retain) UIButton *swapButton;
- (void)swap;
#end
The implementation file:
#import "SwapViewController.h"
#implementation SwapViewController
#synthesize firstView;
#synthesize secondView;
#synthesize swapButton;
- (void)loadView
{
CGRect frame = [[UIScreen mainScreen] applicationFrame];
UIView *containerView = [[UIView alloc] initWithFrame:frame];
containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view = containerView;
[containerView release];
frame = self.view.bounds;
firstView = [[UIView alloc] initWithFrame:frame];
firstView.backgroundColor = [UIColor redColor];
secondView = [[UIView alloc] initWithFrame:frame];
secondView.backgroundColor = [UIColor blueColor];
self.swapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.swapButton.frame = CGRectMake(10, 10, 100, 50);
[swapButton addTarget:self action:#selector(swap) forControlEvents:UIControlEventTouchUpInside];
displayingFirstView = YES;
[self.view addSubview:firstView];
[self.view addSubview:swapButton];
}
- (void)swap
{
if(displayingFirstView) {
[self.firstView removeFromSuperview];
[self.view addSubview:secondView];
displayingFirstView = NO;
} else {
[self.secondView removeFromSuperview];
[self.view addSubview:firstView];
displayingFirstView = YES;
}
[self.view bringSubviewToFront:self.swapButton];
}
#end
sample code;
BOOL firstview = YES; // First, I have added view1 as a subview;
if (firstview) {
[view1 removeFromSuperview];
[self.view addSubview:view2];
} else {
[view2 removeFromSuperview];
self.view addSubview:view1];
}

Is it possible to animate the width of a UIButton of UIButtonStyleCustom type?

I have an animation on frame size which works fine when the UIButton is a UIButtonTypeRoundedRect. But has no visible affect when I am using a UIButtonStyleCustom with background image. My animation code is here:
[UIView beginAnimations:#"MyAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.25];
CGRect tempFrame = myButton.frame;
tempFrame.size.width = tempFrame.size.width + 100.0f;
myButton.frame = tempFrame;
[UIView commitAnimations];
Thanks for the help!
I've tried your example in my XCode. All works fine with both buttons. So some additional questions... Do you use Background or Image? What is view's mode (Scale to Fill or something else)? And where do you test your app (device or simulator, iphone 3 or iphone 4 or ...)?
Also make some checks. Check that myButton is connected in IB (maybe, you've created a new button and forgot to do this). Check that this code runs (maybe, you forgot connection to necessary touch action).
Hey guys, I finally resolve my problem. I subclassed UIView and added two UIImageViews and an UIButton to it. The animation is perfectly good now!
Here is the code:
.h
#import <UIKit/UIKit.h>
#interface NNAnimatableButton : UIView {
UIImageView *backgroundImageView;
UIImageView *imageView;
UIButton *button;
}
#property (nonatomic, retain) UIImageView *backgroundImageView;
#property (nonatomic, retain) UIImageView *imageView;
#property (nonatomic, retain) UIButton *button;
#end
.m
#import "NNAnimatableButton.h"
#implementation NNAnimatableButton
#synthesize backgroundImageView, imageView, button;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
CGRect rect = CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height);
NSUInteger autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
// Initialization code.
backgroundImageView = [[UIImageView alloc] initWithFrame:rect];
backgroundImageView.autoresizingMask = autoresizingMask;
imageView = [[UIImageView alloc] initWithFrame:rect];
imageView.autoresizingMask = autoresizingMask;
imageView.contentMode = UIViewContentModeCenter;
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.autoresizingMask = autoresizingMask;
[button setFrame:rect];
[self addSubview:backgroundImageView];
[self addSubview:imageView];
[self addSubview:button];
[backgroundImageView release];
[imageView release];
}
return self;
}
- (void)dealloc {
[backgroundImageView release];
[imageView release];
[button release];
[super dealloc];
}
#end

How to attach more than one controller to views its subviews

plz help me out
I am a newbie in iphone development its my second sample code. I am trying to add sub-views to a View and generate events according to the view/subview which is touched.i have added subviews in main view and all are showing all at one time. The projects I am experimenting with is a newly created, clean Window-Base application.
I wrote the following code into the one and only viewController's code:
#interface testViewController : UIViewController {
IBOutlet UIView *blueView1;
IBOutlet UIView *blueView2;
: :
IBOutlet UIView *blueView6;
}
//---expose the outlet as a property---
#property (nonatomic, retain) IBOutlet UIView *blueView1;
#property (nonatomic, retain) IBOutlet UIView *blueView2;
: : *blueView6;
//---declaring the action---
-(IBAction) viewClicked: (id) sender;
#end
And its .m file contains (loadView method in which i am attaching subviews to it. They are displaying very well all at one time.what i am trying to do is when my view/subview are touched they will generate an event which should be treated by this single method according to their object which will change the back color of the view/subview accordingly.
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
self.view.backgroundColor = [UIColor greenColor];
// Create a simple blue square
CGRect blueFrame0 = CGRectMake(5, 115, 100, 100);
UIView *blueView0 = [[UIView alloc] initWithFrame:blueFrame0];
blueView0.backgroundColor = [UIColor blueColor];
// Create a simple blue square
CGRect blueFrame1 = CGRectMake(110, 115, 100, 100);
UIView *blueView1 = [[UIView alloc] initWithFrame:blueFrame1];
blueView1.backgroundColor = [UIColor blueColor];
// Create a simple blue square
CGRect blueFrame2 = CGRectMake(215, 115, 100, 100);
UIView *blueView2 = [[UIView alloc] initWithFrame:blueFrame2];
blueView2.backgroundColor = [UIColor blueColor];
//-----------------------------------------------------------------------------------------------------------
// Create a simple blue square
CGRect blueFrame3 = CGRectMake(5, 220, 100, 100);
UIView *blueView3 = [[UIView alloc] initWithFrame:blueFrame3];
blueView3.backgroundColor = [UIColor blueColor];
// Create a simple blue square
CGRect blueFrame4 = CGRectMake(110, 220, 100, 100);
UIView *blueView4 = [[UIView alloc] initWithFrame:blueFrame4];
blueView4.backgroundColor = [UIColor blueColor];
// Create a simple blue square
CGRect blueFrame5 = CGRectMake(215, 220, 100, 100);
UIView *blueView5 = [[UIView alloc] initWithFrame:blueFrame5];
blueView5.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView0];
[self.view addSubview:blueView1];
[self.view addSubview:blueView2];
[self.view addSubview:blueView3];
[self.view addSubview:blueView4];
[self.view addSubview:blueView5];
[blueView0 release];
[blueView1 release];
[blueView2 release];
[blueView3 release];
[blueView4 release];
[blueView5 release];
[self.view release];
}
-(IBAction) viewClickedid) sender {
{view/subview}.backgroundColor = [UIColor blackColor];
}
i worte the delegate in this way
#interface testAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
testViewController *viewController; //for main view
testViewController *viewController1;//for subview1
testViewController *viewController2;//for subview2
testViewController *viewController3;//for subview3
**upto 6 controllers
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet testViewController viewController;
#property (nonatomic, retain) IBOutlet testViewController viewController1;
**upto 6 controllers
#end
In testAppdelegate.m i am making a controller for main view but i dont know how to attach other controllers to other subviews.right now when i touch anywhere on the view the main view color changes.
how can i uniquely identify different subviews touch and make their color change??How to do this????
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
checkAppController *rootController = [checkAppController alloc];
[window addSubview:[rootController view]];
[window makeKeyAndVisible];
}
i am getting all the touches events in this method
- (void)touchesBeganNSSet *)touches withEventUIEvent *)event {
UITouch* touch = [touches anyObject];
NSUInteger numTaps = [touch tapCount];
if ([touches count] > 1)
NSLog(#"mult-touches %d", [touches count]);
if (numTaps < 2) {
}
else {
NSLog(#"double tap");
}
}
It is to do with the way you are structuring your application. For the BlueView1..6 to be handled by a separate view controller, it is that view controller which needs to create the view.
You need to create the view controllers for each blue view inside the main view controller, and then create each blue view inside the blue view inside each blue view controller.