1

我有一个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
4

2 回答 2

0

http://ios.robertlinnemann.com/configure-a-uiscrollview-entirely-in-storyboard-with-interface-builder/非常简单的教程,但可能会有所帮助。

于 2013-05-21T04:02:05.803 回答
0

“其实答案很简单:我只需要将 UIView 从情节提要的场景中移除,然后将 UIScrollView 直接放到 DetailViewController 场景中即可。” -@ingenspor

归功于:我已将 UIScrollView 添加到 UIView(我的详细视图),现在如何显示内容?

于 2013-05-21T04:14:22.630 回答