我有DetailViewController
工作正常。它有标签和textView
。我添加了scrollView
以允许textView
在选中时向上移动,但在我将scrollView
放在旧标签下后,标签不再显示数据。我一直在使用故事板来做UI。我假设我可以放下滚动视图并将标签放在顶部,这样就可以了。它没有。
这是为什么?
更新:
对于那些需要代码的人,这里是:
#import "DetailViewController.h"
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
@synthesize comment;
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3f;
#pragma mark - Managing the detail item
- (void)setDetailItem:(RootBeer*)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
[self.view addSubview:];
if (self.detailItem) {
self.rootBeerNameLabel.text = [[self.detailItem valueForKey:@"rootBeerName"] description];
self.rootBeerBrewerLabel.text = [[self.detailItem valueForKey:@"rootBeerBrewer"] description];
self.rootBeerLocationLabel.text = [[self.detailItem valueForKey:@"rootBeerLocation"] description];
self.rootBeerDescriptionLabel.text = [[self.detailItem valueForKey:@"rootBeerDescription"] description];
self.rootBeerDetailsLabel.text = [[self.detailItem valueForKey:@"rootBeerDetails"] description];
self.rootBeerNotes.text = self.detailItem.comments.rootBeerComment;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)cancel:(id)sender{
NSLog(@"Saved!");
[self.navigationController popToRootViewControllerAnimated:YES];
}
-(IBAction)save:(id)sender{
NSManagedObjectContext *context = [self managedObjectContext];
Comments* com = [NSEntityDescription insertNewObjectForEntityForName:@"Comments" inManagedObjectContext:context];
if(self.detailItem){
//update current job
[com setValue:self.rootBeerNotes.text forKey:@"rootBeerComment"];
[com setValue:[self.detailItem valueForKey:@"rootBeerId"] forKey:@"rootBeerId"];
[self.detailItem setValue:com forKey:@"comments"];
NSError* error = nil;
if(![context save:&error]){
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
NSLog(@"Saved!");
}else{
//create new job
NSManagedObject *newJob = [NSEntityDescription insertNewObjectForEntityForName:@"Jobs" inManagedObjectContext:context];
/*
[newJob setValue:self.company.text forKey:@"company"];
[newJob setValue:self.position.text forKey:@"position"];
[newJob setValue:self.jobId.text forKey:@"jobId"];
[newJob setValue:self.notes.text forKey:@"notes"];
*/
NSError* error = nil;
if(![context save:&error]){
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
NSLog(@"Saved!");
}
[self.navigationController popToRootViewControllerAnimated:YES];
}
-(NSManagedObjectContext *)managedObjectContext{
NSManagedObjectContext* context = nil;
id delegate = [[UIApplication sharedApplication]delegate];
if([delegate performSelector:@selector(managedObjectContext)]){
context=[delegate managedObjectContext];
}
return context;
}
@end
答案 0 :(得分:0)
http://ios.robertlinnemann.com/configure-a-uiscrollview-entirely-in-storyboard-with-interface-builder/非常简单的教程,但可能会有帮助。
答案 1 :(得分:0)
“实际上答案很简单:我只需要从故事板中的场景中删除UIView,然后将UIScrollView直接放在DetailViewController场景上。” - @ingenspor
信用证转到:I've added a UIScrollView to a UIView (my detail view), how to display content now?