0
#import "BirdsDetailViewController.h"
#import "BirdSighting.h"
@interface BirdsDetailViewController ()
- (void)configureView;
@end

@implementation BirdsDetailViewController
-(void)setSighting:(BirdSighting *)sighting
{
    if (_sighting != sighting) {
        _sighting = sighting;
        //Update the view
        [self configureView];
// Is this code[self configureView] necessary which reappears in the later viewDidLoad? 
//After I deleted this line everything seems works well.
    }
}
- (void)configureView
{
// Update the user interface for the detail item.
    BirdSighting *theSighting = self.sighting;
    static NSDateFormatter *formatter = nil;
    if (formatter == nil) {
    formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    }
    if (theSighting) {
    self.birdNameLable.text = theSighting.name;
    self.locationLable.text = theSighting.location;
    self.dateLable.text = [formatter stringFromDate:(NSDate *) theSighting.date];
}

}
- (void)viewDidLoad
{
[super viewDidLoad];
//You see. It reappears here.
[self configureView]; 
}

@end

The code above is quoted from Apple's official sample(Your Second iOS App: Storyboards ). Is this code [self configureView] in the setSighting: necessary which reappears later ?After I deleted this line everything seems works well. Thank you very much.

4

1 に答える 1

1

[self configureView];で 省略できますsetSighting:

そして、あなたが自分自身を実装しているもう1つの理由はsetSighting:、Cocoaがあなたに @property/@synthesizeを提供します。これは信頼でき、特定のことを何もしていないため、コードが短くなります。

于 2013-02-28T04:51:54.773 に答える