I'm a new iPhone developer, and as a learning exercise, I decided to modify the PageControl sample application from the iPhone development site. I want to add a scrolling list of text to each of the seven pages that are displayed within this app.
Using the Interface Builder, I added a UITextView object within the UIView object at the same level as the already existing UILabel object. I then managed this UITextView within the code in a similar way to how the UILabel was being managed (see below for my code).
However, the UITextView only displays text on the first page, and it's empty (or missing?) on all of the other pages. The UILabel displays its text fine on all pages.
I'm sure that I must be doing something wrong, but I can't figure out what.
Here's my code. First, the code from MyViewController.h (the code that I added to the standard sample app is in bold):
Here's my MyViewController.m:
#import "MyViewController.h"
The other source files from this standard sample app are unchanged.
By the way, I connected the outlets for the UITextView object using the Interface Builder in the same way that they were connected for the already existing UILabel (I think!).
So what am I missing? Why is the text in the UITextView only showing up on the first of the seven pages in this app, even though the text in the UILabel shows up on all of these pages?
Thanks in advance.
Using the Interface Builder, I added a UITextView object within the UIView object at the same level as the already existing UILabel object. I then managed this UITextView within the code in a similar way to how the UILabel was being managed (see below for my code).
However, the UITextView only displays text on the first page, and it's empty (or missing?) on all of the other pages. The UILabel displays its text fine on all pages.
I'm sure that I must be doing something wrong, but I can't figure out what.
Here's my code. First, the code from MyViewController.h (the code that I added to the standard sample app is in bold):
Code:
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController {
IBOutlet UILabel *pageNumberLabel;
[B] IBOutlet UITextView *pageText;[/B]
int pageNumber;
}
@property (nonatomic, retain) UILabel *pageNumberLabel;
[B]@property (nonatomic, retain) UITextView *pageText;[/B]
- (id)initWithPageNumber:(int)page;
@end
Here's my MyViewController.m:
#import "MyViewController.h"
Code:
static NSArray *__pageControlColorList = nil;
@implementation MyViewController
@synthesize pageNumberLabel;
[B]@synthesize pageText;[/B]
// Creates the color list the first time this method is invoked. Returns one color object from the list.
+ (UIColor *)pageControlColorWithIndex:(NSUInteger)index {
if (__pageControlColorList == nil) {
__pageControlColorList = [[NSArray alloc] initWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor magentaColor],
[UIColor blueColor], [UIColor orangeColor], [UIColor brownColor], [UIColor grayColor], nil];
}
// Mod the index by the list length to ensure access remains in bounds.
return [__pageControlColorList objectAtIndex:index % [__pageControlColorList count]];
}
// Load the view nib and initialize the pageNumber ivar.
- (id)initWithPageNumber:(int)page {
if (self = [super initWithNibName:@"MyView" bundle:nil]) {
pageNumber = page;
}
return self;
}
- (void)dealloc {
[pageNumberLabel release];
[B] [pageText release];[/B]
[super dealloc];
}
// Set the label and background color when the view has finished loading.
- (void)viewDidLoad {
pageNumberLabel.text = [NSString stringWithFormat:@"Page %d", pageNumber + 1];
[B] pageText.text = [NSString stringWithFormat:@"Text page %d", pageNumber + 1];[/B]
self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
}
@end
The other source files from this standard sample app are unchanged.
By the way, I connected the outlets for the UITextView object using the Interface Builder in the same way that they were connected for the already existing UILabel (I think!).
So what am I missing? Why is the text in the UITextView only showing up on the first of the seven pages in this app, even though the text in the UILabel shows up on all of these pages?
Thanks in advance.
.