#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
上面的代码引用自 Apple 的官方示例(Your Second iOS App: Storyboards)。setSighting: 中的这段代码 [self configureView] 是否需要稍后重新出现?在我删除此行后,一切似乎都运行良好。非常感谢。