I have a multi-screen app anchored by a Navigation Controller. On one screen, static text entered into a UILabel inside a UIScrollView scrolls perfectly. On another screen, I followed that same format to create a scrollable UILabel within it's own UIScrollView - only this time the scrolling text varies based on what's pulled from a plist file that is accessed when a selection is made in a pickerView on the same screen. The result is - the text appears, and changes correctly when a new picker item is selected - but the text won't scroll.
I found this solution, but I can't figure out how to apply it to my situation.
I also read about using a UITextView instead of the UILabel, but I can't figure out how to create the referencing outlet to it in the Connections Inspector on the storyboard in Xcode (v.4.5). I assume there may be a way to code this instead of relying on the graphic interface.
Here is the relevant portion of my implementation file. The "Term" is selected in the pickerView and the "Definition" is what appears in the UILabel:
@implementation InsuranceGlossaryViewController
@synthesize termPicker, termArray, definitionArray;
@synthesize termLabel, definitionLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(280, 2400)];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Glossary" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.termArray = [dict objectForKey:@"Term"];
self.definitionArray = [dict objectForKey:@"Definition"];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
self.termArray = nil;
self.definitionArray = nil;
self.termLabel = nil;
self.definitionLabel = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [termArray count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [termArray objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *resultString = [[NSString alloc] initWithFormat:
@"%@",
[definitionArray objectAtIndex:row]];
definitionLabel.text = resultString;
NSString *termString = [[NSString alloc] initWithFormat:
@"%@",
[termArray objectAtIndex:row]];
termLabel.text = termString;
}
And here is code from the header file:
@interface InsuranceGlossaryViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource, MFMailComposeViewControllerDelegate>
{
UIPickerView *termPicker;
NSArray *termArray;
NSArray *definitionArray;
UILabel *termLabel;
UILabel *definitionLabel;
IBOutlet UIScrollView *scroller;
}
- (IBAction)showEmail:(id)sender;
@property (strong, nonatomic) IBOutlet UIPickerView *termPicker;
@property (strong, nonatomic) IBOutlet UILabel *termLabel;
@property (strong, nonatomic) IBOutlet UILabel *definitionLabel;
@property (strong, nonatomic) NSArray *termArray;
@property (strong, nonatomic) NSArray *definitionArray;
Any help would be greatly appreciated.
EDIT: I appear to have gotten a UITextView field up and running - at least I can see it scrolling when I swipe in it. What I can't figure out is how to get "definitionLabel" to appear in it. With the UILabel, I was able to set up a Referencing Outlet to definitionLabel. But the UITextView doesn't work the same way. I'm stumped and my boss wants this app to go live this month!