In an iPhone app for iOS5 I’m trying to create a controller object that contains an image sub-view with multiple UIImageViews. I have a main view controller with its associated main view and within this main view I have an multi-image sub-view and this sub-view has a dozen or more UIImageViews as configured in Interface Builder. I have created a descendent of UIView and connected it as an IBOutlet connection for the ImageSubView in my ViewController. I want to create IBOutlets for the dozen UIImageViews within my subView class, but Interface Builder will only let me create IBOutlets in my main ViewController not in the ImageSubView class. That is when I control drag from one of the UIImageViews it only shows creation of an IBOutlet if I drag within the MainViewController @interface code but not to the ImageSubView @interface code. I want the details of controlling these dozen images to be hidden from the main ViewController. I want the main ViewController to communicate to the ImageSubView only and for the ImageSubView to know how to manipulate the dozen images within it. Do I need to create a sub-viewController? If so how do I create a sub-viewController within the current main view? Interface Builder wouldn’t let me drag another ViewController into the current main view. Can there be multiple viewControllers (a main one and sub-controllers) for a single screen?
The view hierarchy looks like this:
MainViewController
MainView
ImageViewFullBackground
ImageSubView
UIImageView1
UIImageView2
. . .
UIImageView12
Button1
Button2
. . .
Button10
In response to Allen here is my ImageSubView header. The class is actually called UILedNumericView
//
// UINumericLabel.h
// UILedNumericView
//
// Created by Jon D. Newbill on 2/18/12.
// Copyright (c) 2012 Bitworks Systems Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface UILedNumericView : UIView
@property (copy,nonatomic) NSString * text;
// This is the numeric value of the LED display as a double
@property (nonatomic) double value;
// Returns true if the numeric display contains a decimal point
@property (readonly,nonatomic) BOOL hasDecimalPoint;
// Returns true if numeric display contains an exponent
@property (readonly,nonatomic) BOOL hasExponent;
// Returns true if numeric display is equal to zero.
@property (readonly,nonatomic) BOOL isZero;
// Returns number of characters in entire display
@property (readonly,nonatomic) NSUInteger length;
// Returns zero based character index of the E in the display
@property (readonly,nonatomic) NSUInteger exponentIndex;
// Returns or sets mantissa portion of display. This is everything
// preceding the "E" on the display or the entire display if it does
// not contain an "E";
@property (copy, nonatomic) NSString * mantissa;
// Returns or sets exponent portion of display. This is everything
// following the "E" on the display. If no E exists then an empty
// string is returned. When set to a non-zero length string an E will
// be added to the display.
@property (copy, nonatomic) NSString * exponent;
// Returns maximum allowed characters in display
// This includes digits, sign, decimal point and exponent
+ (NSUInteger) maxLength;
@end
You can get the subviews from any view you have already gotten an IBOutlet from the interfacebuilder like this:
There is no need for you to create a viewcontroller or something. However it is possible if you want but I don’t believe it is what you want.
Edit: IBOutlets, as their name imply are used to tell the compiler to make a pointer to an item in the interface builder, so if you follow what I posted you are still creating those pointers programatically. If you want to have the “global” convenience of these as the IBOutlets have, just create a property for an UIView instead of declaring them locally like I did.
Edit2: Forgot to mention that the order of the views is the same as the order in the interface builder from top to down. (unless you changed them programatically)