今天繼續(xù)耙册,這兩天的程序比較小丙唧,所以能連著更新兩天。
在今天的這個ShutterbugC中觅玻,老爺子用了好多的setter和getter。向我們展示了各種情況培漏。
比如惰性初始化溪厘。
- (UIImageView *)imageView
{
if (!_imageView)
{
_imageView = [[UIImageView alloc] init];
}
return _imageView;
}
還有這個...
- (UIImage *)image
{
return self.imageView.image;
}
- (void)setImage:(UIImage *)image
{
self.imageView.image = image;
self.scrollView.zoomScale = 1.0;
self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
self.scrollView.contentSize = self.image ? self.image.size : CGSizeZero;
}
除此之外,還有NSURL的使用
NSURLRequest *request = [NSURLRequest requestWithURL:self.imageURL];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request
completionHandler:^(NSURL *localfile, NSURLResponse *response, NSError *error){
if (!error)
{
if ([request.URL isEqual:self.imageURL])
{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:localfile]];
dispatch_async(dispatch_get_main_queue(), ^{
self.image = image;
});
}
}
}];
[task resume];
最后要說的就是tableView牌柄。這個說過的人太多了畸悬,就不多說了。只說一點珊佣,就是關(guān)于在StoryBoard中添加refresh control蹋宦。這個當(dāng)時視頻沒好好看,最后只要問度娘咒锻。
屏幕快照 2016-11-01 下午11.35.44.png
只要把里面的Refreshing設(shè)置成為Enabled的冷冗,refresh control控件就會自動添加了。
要說明下惑艇,老爺爺?shù)某绦蚴莍pad和iPhone 都支持的蒿辙,但是我把ipad部分選擇性遺忘了...所以..就這樣吧
最后,程序地址:https://github.com/Labrador2008/STF_iOS7/tree/master/ShutterbugC