我有一个由导航控制器锚定的多屏幕应用程序。在一个屏幕上,输入到UIScrollView内的UILabel的静态文本完美滚动。在另一个屏幕上,我遵循相同的格式在其自己的UIScrollView中创建一个可滚动的UILabel - 只是这次滚动文本根据从选择被访问时访问的plist文件中提取的内容而变化在同一屏幕上的pickerView中。结果是 - 文本出现,并在选择新的选择器项目时正确更改 - 但文本不会滚动。
我找到了this solution,但我无法弄清楚如何将其应用到我的情况中。
我还读到了使用UITextView而不是UILabel,但我无法弄清楚如何在Xcode(v.4.5)的故事板上的Connections Inspector中为它创建引用插座。我假设可能有一种方法来编码,而不是依赖于图形界面。
以下是我的实施文件的相关部分。 " Term"在pickerView和"定义"中被选中出现在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;
}
以下是头文件中的代码:
@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;
非常感谢任何帮助。
编辑:我似乎已经启动并运行了一个UITextView字段 - 至少我可以看到它在我滑动时滚动。我无法弄清楚如何获得&#34; definitionLabel&#34;出现在其中。通过UILabel,我能够为DefinitionLabel设置一个Referencing Outlet。但UITextView的工作方式并不相同。我很难过,我的老板希望这个应用程序能在这个月上线!
答案 0 :(得分:0)
解决。
我添加了“UITextFieldDelegate”和“IBOutlet UITextView * textView;”到.h文件并添加了“textView.text = resultString;”到.m文件,这允许我将UITextView的引用插座绑定到textView。现在,正确的文本出现在UITextView中并滚动。