{"id":9669,"date":"2013-12-10T12:00:22","date_gmt":"2013-12-10T03:00:22","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=9669"},"modified":"2013-12-11T17:52:54","modified_gmt":"2013-12-11T08:52:54","slug":"%e3%81%aa%e3%82%81%e3%82%89%e3%81%8b%e3%81%ab%e5%8b%95%e4%bd%9c%e3%81%99%e3%82%8buitableview%e3%81%ae%e3%81%a4%e3%81%8f%e3%82%8a%e3%81%8b%e3%81%9f","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2013\/12\/9669\/","title":{"rendered":"\u306a\u3081\u3089\u304b\u306b\u52d5\u4f5c\u3059\u308bUITableView\u306e\u3064\u304f\u308a\u304b\u305f"},"content":{"rendered":"<p>\u77e2\u53e3\u88d5\u4e5f\u3067\u3059\u3002<\/p>\n<p>Advent Calendar 10\u65e5\u76ee\u306fiOS\u306eUITableView\u306e\u8a71\u3092\u3057\u307e\u3059\u3002<\/p>\n<h3 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_0\">\u307c\u3084\u304d<\/h3>\n<p>iOS\u30a2\u30d7\u30ea\u3092\u958b\u767a\u3057\u3066\u3044\u308b\u306870%\u304f\u3089\u3044\u306e\u6642\u9593\u306fUITableView\u306b\u8cbb\u3084\u3057\u3066\u3044\u308b\u6c17\u304c\u3057\u3066\u304d\u307e\u3059\u3002<br \/>\nUITableView\u306f\u975e\u5e38\u306b\u3081\u3093\u3069\u3046\u306a\u3082\u306e\u3067\u3059\u304c\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u30b7\u30d3\u30a2\u3067\u304b\u3064\u30e6\u30fc\u30b6\u30fc\u306e\u5feb\u9069\u3055\u306b\u76f4\u7d50\u3059\u308b\u3082\u306e\u306a\u306e\u3067\u5927\u3044\u306b\u624b\u9593\u3092\u304b\u3051\u308b\u4fa1\u5024\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u30ac\u30af\u30ac\u30af\u51e6\u7406\u843d\u3061\u3059\u308bUITableView\u3092\u4f8b\u3068\u3057\u3066\u6539\u5584\u3057\u3066\u3044\u304d\u306a\u304c\u3089\u5feb\u9069\u306aUITableView\u306e\u3064\u304f\u308a\u304b\u305f\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h3 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_1\">\u76ee\u7684<\/h3>\n<p>\u4ee5\u4e0b\u306e\u30b1\u30fc\u30b9\u30b9\u30bf\u30c7\u30a3\u3067\u306f\u6b21\u306e\u76ee\u7684\u3067\u30b3\u30fc\u30c9\u3092\u6539\u5584\u3057\u3066\u3044\u304d\u307e\u3059<\/p>\n<ul>\n<li> \u306a\u3081\u3089\u304b\u306b\u52d5\u304f\u3088\u3046\u306b\u3059\u308b<\/li>\n<\/ul>\n<p>\u3053\u3053\u3067\u306e\u30dd\u30a4\u30f3\u30c8\u306f\u5b9f\u969b\u901f\u304f\u306a\u304f\u3066\u3082\u30e6\u30fc\u30b6\u304c\u5feb\u9069\u306b\u611f\u3058\u308c\u3070OK\u3067\u3042\u308b\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u51e6\u7406\u901f\u5ea6\u304c\u9ad8\u901f\u3067\u3042\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h3 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_2\">\u6226\u7565<\/h3>\n<p>UITableView\u3067\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u554f\u984c\u306f\u6b21\u306e2\u70b9\u3067\u3042\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059<\/p>\n<ul>\n<li> \u30b9\u30af\u30ed\u30fc\u30eb\u304c\u30ac\u30af\u3064\u304f<\/li>\n<li> loadMore\u30670.5\u301c\u6570\u79d2\u56fa\u307e\u308b<\/li>\n<\/ul>\n<h4 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_3\">\u30b9\u30af\u30ed\u30fc\u30eb\u304c\u30ac\u30af\u3064\u304f<\/h4>\n<p>\u3053\u308c\u306fcellForRowAtIndexPath:\u306e\u5b9f\u884c\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u308b\u3053\u3068\u3001\u307e\u305f\u306f\u63cf\u753b\u81ea\u4f53\u304c\u91cd\u3044\u3053\u3068\u306e\u3044\u305a\u308c\u304b\u304c\u539f\u56e0\u3067\u3059\u3002<br \/>\n\u524d\u8005\u306b\u3064\u3044\u3066\u306fcellForRowAtIndexPath:\u306f\u30e1\u30a4\u30f3\u30b9\u30ec\u30c3\u30c9\u3067\u5b9f\u884c\u3055\u308c\u308b\u305f\u3081\u3001\u51e6\u7406\u306b\u6642\u9593\u304c\u304b\u304b\u308b\u3068\u305d\u306e\u9593\u3001\u753b\u9762\u306e\u66f4\u65b0\u304c\u6b62\u307e\u3063\u3066\u3057\u307e\u3044\u3001\u30b9\u30af\u30ed\u30fc\u30eb\u304c\u30ac\u30af\u30ac\u30af\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u30e1\u30bd\u30c3\u30c9\u306e\u5b9f\u884c\u6642\u9593\u3092\u77ed\u304f\u3059\u308b\u3053\u3068\u3067\u6539\u5584\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u5f8c\u8005\u306b\u3064\u3044\u3066\u306f\u3001\u753b\u50cf\u306e\u30ea\u30b5\u30a4\u30ba\u3001\u89d2\u4e38\u306a\u3069\u91cd\u3044\u63cf\u753b\u6642\u52a0\u5de5\u3092\u884c\u308f\u306a\u3044\u3053\u3068\u3001\u30d6\u30ec\u30f3\u30c9\u30ec\u30a4\u30e4\u30fc\u3092\u6e1b\u3089\u3059\u3053\u3068\u3067\u6539\u5584\u3067\u304d\u307e\u3059\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_4\">loadMore\u30670.5\u301c\u6570\u79d2\u56fa\u307e\u308b<\/h4>\n<p>\u3053\u308c\u306f\u591a\u304f\u306e\u5834\u5408\u3001cell\u306einsert, delete, reload\u3067\u547c\u3070\u308c\u308btableView:heightForRowAtIndexPath:\u306e\u5b9f\u884c\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u539f\u56e0\u3067\u3059\u3002<br \/>\ntableView:heightForRowAtIndexPath:\u306f\u30e1\u30a4\u30f3\u30b9\u30ec\u30c3\u30c9\u3067\u5b9f\u884c\u3055\u308c\u308b\u305f\u3081\u3001\u51e6\u7406\u306b\u6642\u9593\u304c\u304b\u304b\u308b\u3068\u305d\u306e\u9593\u3001\u753b\u9762\u306e\u66f4\u65b0\u3068\u64cd\u4f5c\u306e\u53d7\u4ed8\u304c\u6b62\u307e\u3063\u3066\u3057\u307e\u3044\u3001\u30e6\u30fc\u30b6\u30fc\u306b\u30d5\u30ea\u30fc\u30ba\u3057\u305f\u3088\u3046\u306a\u611f\u899a\u3092\u4e0e\u3048\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u30e1\u30bd\u30c3\u30c9\u306e\u5b9f\u884c\u6642\u9593\u3092\u77ed\u304f\u3059\u308b\u3053\u3068\u3067\u6539\u5584\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_5\">\u7528\u610f\u3059\u308b\u3082\u306e<\/h3>\n<ul>\n<li> \u306a\u308b\u3079\u304f\u9045\u3044iOS\u7aef\u672b<\/li>\n<\/ul>\n<p>\u901f\u3044\u7aef\u672b\u3067\u306f\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306e\u52b9\u679c\u304c\u78ba\u8a8d\u3057\u306b\u304f\u3044\u3067\u3059\u3002\u5c11\u306a\u304f\u3068\u3082\u30e1\u30a4\u30f3\u30bf\u30fc\u30b2\u30c3\u30c8\u3068\u3057\u3066\u3044\u308b\u7aef\u672b\u306e1\u4e16\u4ee3\u524d\u306e\u3082\u306e\u3092\u7528\u610f\u3057\u307e\u3057\u3087\u3046\u3002iOS7\u3067\u3042\u308c\u3070iPhone4\u3042\u305f\u308a\u304c\u304a\u3059\u3059\u3081\u3067\u3059\u3002<\/p>\n<h3 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_6\">\u52b9\u679c\u306e\u6e2c\u5b9a\u65b9\u6cd5<\/h3>\n<p>\u9045\u3044\u7aef\u672b\u3067\u30a2\u30d7\u30ea\u3092\u89e6\u3063\u3066\u78ba\u304b\u3081\u307e\u3059\u3002<br \/>\n\u5feb\u9069\u3063\u307d\u304f\u611f\u3058\u305f\u3089\u52b9\u679c\u304c\u3042\u3063\u305f\u3068\u8003\u3048\u3066\u3088\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\n\u9006\u306b\u9045\u3044\u7aef\u672b\u3067\u52b9\u679c\u304c\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306f\u52b9\u679c\u304c\u306a\u3044\u3068\u8003\u3048\u3066\u3044\u3044\u3067\u3057\u3087\u3046\u3002\u6570\u5b57\u306f\u53c2\u8003\u7a0b\u5ea6\u3067\u30d5\u30a3\u30fc\u30ea\u30f3\u30b0\u3092\u5927\u5207\u306b\u3002<\/p>\n<h3 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_7\">\u30b5\u30f3\u30d7\u30eb\u30a2\u30d7\u30ea<\/h3>\n<p>\u4f8b\u3068\u3057\u3066\u4f55\u304b\u306e\u30b3\u30e1\u30f3\u30c8\u3092\u8868\u793a\u3059\u308b\u30a2\u30d7\u30ea\u3092\u8003\u3048\u3066\u307f\u307e\u3059<\/p>\n<p><a href=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2013\/12\/ips.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2013\/12\/ips.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\" width=\"434\" height=\"704\" class=\"alignnone size-full wp-image-9692\" \/><\/a><\/p>\n<p>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u3053\u3061\u3089\u3067\u3059:<br \/>\n<a href=\"https:\/\/github.com\/yayugu\/UITableViewExamples\">https:\/\/github.com\/yayugu\/UITableViewExamples<\/a><br \/>\nslowExample\u306e\u65b9\u3092\u52d5\u304b\u3057\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u308f\u304b\u308a\u307e\u3059\u304c\u3001\u975e\u5e38\u306b\u91cd\u304f\u3001AppStore\u306e\u30ec\u30d3\u30e5\u30fc\u3067\u300c<strong>\u91cd\u3059\u304e\u306a\u306e\u3067 \u26061\u3064<\/strong>\u300d\u3068\u66f8\u304b\u308c\u305d\u3046\u306a\u30af\u30aa\u30ea\u30c6\u30a3\u30fc\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u6539\u5584\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n<\/p>\n<h4 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_8\">\u901a\u4fe1\u306f\u5fc5\u305aasynchronous\u3067\u884c\u3046<\/h4>\n<p>\u5f53\u305f\u308a\u524d\u306e\u3053\u3068\u304b\u3068\u601d\u308f\u308c\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u7279\u306b\u4e0d\u6163\u308c\u306a\u65b9\u304c\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u3067\u4f55\u5ea6\u304b\u540c\u671f\u901a\u4fe1\u3092\u884c\u3063\u3066\u3044\u308b\u30b3\u30fc\u30c9\u3092\u898b\u305f\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u901a\u4fe1\u306f\u5fc5\u305a\u975e\u540c\u671f\u3067\u884c\u3046\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h5 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_9\"> JSON\u306e\u8aad\u307f\u8fbc\u307f\u3092\u975e\u540c\u671f\u306b<\/h5>\n<p><a href=\"https:\/\/github.com\/yayugu\/UITableViewExamples\/commit\/8662980566de2048ce898643741fa203c1cb57ed\" target=\"_blank\">https:\/\/github.com\/yayugu\/UITableViewExamples\/commit\/8662980566de2048ce898643741fa203c1cb57ed<\/a><\/p>\n<p>ViewControllers\/YYTableViewController.m<\/p>\n<p>before<\/p>\n<pre lang=\"objc\">\n<ul>\n<li> (void)viewDidLoad<\/li>\n<\/ul>\n\n{\n    [super viewDidLoad];\n\n    _commentList = [[YYCommentList alloc] initWithDelegate:nil];\n    [_commentList requestSynchronous];\n}\n\n<ul>\n<li> (void)scrollViewDidScroll:(UIScrollView *)scrollView<\/li>\n<\/ul>\n\n{\n    CGFloat contentOffsetWidthWindow = self.tableView.contentOffset.y + self.tableView.bounds.size.height;\n    BOOL leachToBottom = contentOffsetWidthWindow &gt;= self.tableView.contentSize.height;\n    if (!leachToBottom) return;\n    [self.indicator startAnimating];\n    [self.commentList requestMoreSynchronous];\n    [self.indicator stopAnimating];\n}\n<\/pre>\n<p>after<\/p>\n<pre lang=\"objc\">\n<ul>\n<li> (void)viewDidLoad<\/li>\n<\/ul>\n\n{\n    [super viewDidLoad];\n\n    _commentList = [[YYCommentList alloc] initWithDelegate:self];\n    [_commentList requestAsynchronous];\n}\n\n<ul>\n<li> (void)scrollViewDidScroll:(UIScrollView *)scrollView<\/li>\n<\/ul>\n\n{\n    CGFloat contentOffsetWidthWindow = self.tableView.contentOffset.y + self.tableView.bounds.size.height;\n    BOOL leachToBottom = contentOffsetWidthWindow &gt;= self.tableView.contentSize.height;\n    if (!leachToBottom || _commentList.loading) return;\n    [_indicator startAnimating];\n    [_commentList requestMoreAsynchronous];\n}\n\n#pragma mark - Comment List delegate\n\n<ul>\n<li> (void)commentListDidLoad<\/li>\n<\/ul>\n\n{\n    [_indicator stopAnimating];\n    [self.tableView reloadData];\n}\n<\/pre>\n<p><\/p>\n<h5 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_10\">\u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f\u3092\u975e\u540c\u671f\u306b<\/h5>\n<p><a href=\"https:\/\/github.com\/yayugu\/UITableViewExamples\/commit\/c70b863ce864a715a7019da83b226bd7817d2f1c\" target=\"_blank\">https:\/\/github.com\/yayugu\/UITableViewExamples\/commit\/c70b863ce864a715a7019da83b226bd7817d2f1c<\/a><\/p>\n<p>Views\/YYCommentCell.m<\/p>\n<pre lang=\"diff\">\n - (void)setComment:(YYComment *)comment\n {\n     _comment = comment;\n     _name.text = comment.name;\n     _commentText.text = comment.text;\n<ul>\n<li>    _icon.image = [YYImageLoader imageWithURL:comment.iconURL];<\/li>\n<li>    [YYImageLoader imageWithURL:comment.iconURL completion:^(UIImage *image, NSError *error) {<\/li>\n<li>        if (error) return;<\/li>\n<li>        _icon.image = image;<\/li>\n<li>    }];<\/li>\n<\/ul>\n\n}\n<\/pre>\n<h4 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_11\">\u753b\u50cf\u306f\u5225\u30b9\u30ec\u30c3\u30c9\u3067\u30ea\u30b5\u30a4\u30ba&amp;\u89d2\u4e38\u5316\u3057\u3066\u304b\u3089\u30e1\u30a4\u30f3\u30b9\u30ec\u30c3\u30c9\u306b\u6301\u3063\u3066\u304f\u308b<\/h4>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306aUIImageView\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u4f4e\u4e0b\u3055\u305b\u3066\u3057\u307e\u3046\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li> \u8868\u793a\u3059\u308b\u30b5\u30a4\u30ba\u3068\u753b\u50cf\u306e\u30b5\u30a4\u30ba\u304c<strong>\u4e00\u81f4\u3057\u3066\u3044\u306a\u3044<\/strong><\/li>\n<li> CALayer\u3067<strong>\u89d2\u4e38<\/strong>\u306b\u3057\u3066\u3044\u308b<\/li>\n<li> \u900f\u904e\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b<\/li>\n<\/ul>\n<p>\u3053\u308c\u3089\u306e\u554f\u984c\u306f\u5225\u30b9\u30ec\u30c3\u30c9\u3067UIImage\u3092\u52a0\u5de5\u3059\u308b\u3053\u3068\u3067\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306e\u4f8b\u3067\u306f<\/p>\n<ul>\n<li> \u30ea\u30b5\u30a4\u30ba<\/li>\n<li> \u767d\u80cc\u666f\u5857\u308a\u3064\u3076\u3057<\/li>\n<li> \u89d2\u4e38<\/li>\n<li> \u67a0\u7dda<\/li>\n<\/ul>\n<p>\u306e\u51e6\u7406\u3092\u884c\u3063\u305fUIImage\u3092\u4f5c\u6210\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f<\/p>\n<p>\u753b\u50cf\u52a0\u5de5\u306e\u30b3\u30fc\u30c9\u306b\u3064\u3044\u3066\u306f\u9577\u304f\u306a\u308b\u306e\u3067\u30b3\u30df\u30c3\u30c8\u30ed\u30b0\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/yayugu\/UITableViewExamples\/commit\/c92b9b368bd0b817283612d6116e9ab06ed93944\">https:\/\/github.com\/yayugu\/UITableViewExamples\/commit\/c92b9b368bd0b817283612d6116e9ab06ed93944<\/a><\/p>\n<p>CommentCell\u306e\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u3001CALayer\u306eborderWidth, cornerRadius\u3092\u6307\u5b9a\u3059\u308b\u7b87\u6240\u304c\u524a\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre lang=\"diff\">\n @implementation YYCommentCell\n\n<ul>\n<li>\n\n<ul>\n<li> (void)awakeFromNib<\/li>\n<\/ul>\n<\/li>\n<li>{<\/li>\n<li>    _icon.layer.borderWidth = 1.0;<\/li>\n<li>    _icon.layer.cornerRadius = 5.0;<\/li>\n<li>}<\/li>\n<li><\/li>\n<\/ul>\n\n\n...\n\n<ul>\n<li> (void)setComment:(YYComment *)comment<\/li>\n<\/ul>\n\n {\n     _comment = comment;\n     _name.text = comment.name;\n     _commentText.text = comment.text;\n<ul>\n<li>    [YYImageLoader imageWithURL:comment.iconURL completion:^(UIImage *image, NSError *error) {<\/li>\n<li>    [YYImageLoader commentCellImageWithURL:comment.iconURL completion:^(UIImage *image, NSError *error) {<\/li>\n<\/ul>\n\n         if (error) return;\n         _icon.image = image;\n     }];\n }\n<\/pre>\n<p><\/p>\n<h4 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_12\">cell height\u8a08\u7b97\u306b\u306f\u5c02\u7528\u306eLayout\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3001UIView\u3092\u4f7f\u7528\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b<\/h4>\n<p>UITableViewCell\u3067\u306f\u5168\u3066\u306ecell\u306e\u9ad8\u3055\u306f\u8ffd\u52a0\u6642\u306b\u8a08\u7b97\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002iOS7\u304b\u3089\u306festimateHeight\u7cfb\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u6307\u5b9a\/\u30e1\u30bd\u30c3\u30c9\u5b9a\u7fa9\u306b\u3088\u308a\u6b63\u78ba\u306a\u9ad8\u3055\u306e\u8a08\u7b97\u3092\u30b9\u30af\u30ed\u30fc\u30eb\u6642\u307e\u3067\u9045\u5ef6\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u3044\u305a\u308c\u306b\u305b\u3088cellForRowAtIndexPath:\u3088\u308a\u3082\u524d\u306b\u9ad8\u3055\u304c\u6c7a\u5b9a\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306fcell\u306b\u5024\u3092assign\u3057\u3001UIView\u306esystemLayoutSizeFittingSize:\u3092\u5229\u7528\u3057\u3066AutoLayout\u3067\u8a08\u7b97\u3055\u308c\u305f\u9ad8\u3055\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre lang=\"objc\">\n<ul>\n<li> (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath<\/li>\n<\/ul>\n\n{\n    YYCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@\"Cell\"];\n    cell.comment = [_commentList commentAtIndex:indexPath.row];\n    CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];\n    return size.height;\n}\n<\/pre>\n<p>\u3053\u308c\u306f\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u304c\u306a\u304f\u7c21\u6f54\u306b\u66f8\u3051\u308b\u65b9\u6cd5\u3067\u3059\u304c<strong>\u975e\u5e38\u306b\u9045\u3044<\/strong>\u3067\u3059\u3002<br \/>\n\u4e0b\u306e\u3088\u3046\u306blayout\u5c02\u7528\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u9ad8\u3055\u306e\u8a08\u7b97\u3092\u81ea\u5206\u3067\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u5927\u5e45\u306b\u9ad8\u901f\u5316\u3067\u304d\u3001loadMore\u6642\u306e\u30d5\u30ea\u30fc\u30ba\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre lang=\"objc\">\n<ul>\n<li> (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath<\/li>\n<\/ul>\n\n{\n    YYComment *comment = [_commentList commentAtIndex:indexPath.row];\n    return [[YYCommentCellLayout alloc] initWithComment:comment cellWidth:self.view.bounds.size.width].height;\n}\n<\/pre>\n<p>Layouts\/YYCommentCellLayout.h<\/p>\n<pre lang=\"objc\">\n#import <UIKit\/UIKit.h>\n\n@class YYComment;\n\n@interface YYCommentCellLayout : NSObject\n\n<ul>\n<li> (instancetype)initWithComment:(YYComment*)comment cellWidth:(CGFloat)cellWidth;<\/li>\n<li> (CGFloat)height;<\/li>\n<li> (CGRect)nameRect;<\/li>\n<li> (CGRect)commentTextRect;<\/li>\n<\/ul>\n\n\n@end\n<\/pre>\n<p>Layouts\/YYCommentCellLayout.m<\/p>\n<pre lang=\"objc\">\n#import \"YYCommentCellLayout.h\"\n#import \"YYComment.h\"\n\nstatic const CGFloat YYCommentCellLayoutHeightMinimum = 70;\nstatic const CGFloat YYCommentCellLayoutTopPadding = 10;\nstatic const CGFloat YYCommentCellLayoutBottomPadding = 10;\nstatic const CGFloat YYCommentCellLayoutNameCommentTextMargin = 10;\nstatic const CGFloat YYCommentCellLayoutTextLeftPadding = 70;\nstatic const CGFloat YYCommentCellLayoutTextRightPadding = 10;\n\n@interface YYCommentCellLayout ()\n\n@property (nonatomic, strong) YYComment *comment;\n@property (nonatomic) CGFloat cellWidth;\n\n@end\n\n@implementation YYCommentCellLayout\n\n<ul>\n<li> (instancetype)initWithComment:(YYComment*)comment cellWidth:(CGFloat)cellWidth<\/li>\n<\/ul>\n\n{\n    self = [super init];\n    if (self) {\n        _comment = comment;\n        _cellWidth = cellWidth;\n    }\n    return self;\n}\n\n<ul>\n<li> (CGFloat)height<\/li>\n<\/ul>\n\n{\n    CGFloat calculateHeight =\n        YYCommentCellLayoutTopPadding\n        + [self nameSize].height\n        + YYCommentCellLayoutNameCommentTextMargin\n        + [self commentTextSize].height\n        + YYCommentCellLayoutBottomPadding;\n    return MAX(calculateHeight, YYCommentCellLayoutHeightMinimum);\n}\n\n<ul>\n<li> (CGRect)nameRect<\/li>\n<\/ul>\n\n{\n    return (CGRect) {\n        .origin.x = YYCommentCellLayoutTextLeftPadding,\n        .origin.y = YYCommentCellLayoutTopPadding,\n        .size = [self nameSize],\n    };\n}\n\n<ul>\n<li> (CGRect)commentTextRect<\/li>\n<\/ul>\n\n{\n    return (CGRect) {\n        .origin.x = YYCommentCellLayoutTextLeftPadding,\n        .origin.y = YYCommentCellLayoutTopPadding + [self nameSize].height + YYCommentCellLayoutNameCommentTextMargin,\n        .size = [self commentTextSize],\n    };\n}\n\n# pragma mark - Internals\n\n<ul>\n<li> (CGSize)nameSize<\/li>\n<\/ul>\n\n{\n    return (CGSize) {\n        .width = _cellWidth - YYCommentCellLayoutTextLeftPadding - YYCommentCellLayoutTextRightPadding,\n        .height = 15.0,\n    };\n}\n\n<ul>\n<li> (CGSize)commentTextSize<\/li>\n<\/ul>\n\n{\n    CGSize sizeMax = (CGSize) {\n        .width = _cellWidth - YYCommentCellLayoutTextLeftPadding - YYCommentCellLayoutTextRightPadding,\n        .height = CGFLOAT_MAX,\n    };\n    NSDictionary *attr = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:15.0]};\n    return [_comment.text boundingRectWithSize:sizeMax options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size;\n}\n\n@end\n<\/pre>\n<p><\/p>\n<h4 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_13\">\u4eca\u56de\u3084\u3089\u306a\u304b\u3063\u305f\u3053\u3068<\/h4>\n<ul>\n<li> \u52a0\u5de5\u3057\u305f\u753b\u50cf\u306e\u30ad\u30e3\u30c3\u30b7\u30e5<\/li>\n<\/ul>\n<p>view\u306e\u306a\u3081\u3089\u304b\u3055\u306b\u306f\u76f4\u63a5\u5f71\u97ff\u3057\u306a\u3044\u305f\u3081\u884c\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u304c\u3001\u5b9f\u969b\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u884c\u3063\u305f\u307b\u3046\u304c\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li> cell height\u8a08\u7b97\u3092\u5225\u30b9\u30ec\u30c3\u30c9\u3067\u884c\u3044\u30ad\u30e3\u30c3\u30b7\u30e5<\/li>\n<\/ul>\n<p>\u4eca\u56de\u306f\u884c\u308f\u306a\u304f\u3066\u3082\u5341\u5206\u306a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u5f97\u3089\u308c\u305f\u305f\u3081\u884c\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u3088\u308a\u8907\u96d1\u306alayout, \u5927\u91cf\u306ecell\u306e\u8ffd\u52a0\u306a\u3069\u3067cell\u306e\u8ffd\u52a0\u304c\u91cd\u304f\u306a\u308b\u5834\u5408\u306b\u306f\u884c\u3063\u305f\u307b\u3046\u304c\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h3 id=\"hs_edb43c69a0f857df38e32c582184cd28_header_14\">\u307e\u3068\u3081<\/h3>\n<ul>\n<li> main thread\u3092\u6975\u529b\u30ed\u30c3\u30af\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b<\/li>\n<li> heightForRowAtIndexPath, cellForRowAtIndexPath\u3092\u9ad8\u901f\u306b\u3059\u308b<\/li>\n<li> blend layer\u3092\u6975\u529b\u6392\u9664\u3059\u308b<\/li>\n<li> \u753b\u50cf\u306e\u52a0\u5de5\u3092\u884c\u308f\u306a\u3044<\/li>\n<\/ul>\n<p>\u3081\u3093\u3069\u3046\u306a\u4f5c\u696d\u3067\u3059\u304c\u3001\u3053\u3046\u3044\u3063\u305f\u6539\u5584\u306e\u7a4d\u307f\u91cd\u306d\u304c\u30cd\u30a4\u30c6\u30a3\u30d6\u3067\u3057\u304b\u5b9f\u73fe\u3067\u304d\u306a\u3044\u6c17\u6301\u3061\u3044\u3044\u30a2\u30d7\u30ea\u3092\u3064\u304f\u308b\u306e\u3067\u3059\uff01<br \/>\n<\/p>\n<p>\u660e\u65e5\u306fkyo_ago\u3055\u3093\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u77e2\u53e3\u88d5\u4e5f\u3067\u3059\u3002 Advent Calendar 10\u65e5\u76ee\u306fiOS\u306eUITableView\u306e\u8a71\u3092\u3057\u307e\u3059\u3002 \u307c\u3084\u304d iOS\u30a2\u30d7\u30ea\u3092\u958b\u767a\u3057\u3066\u3044\u308b\u306870%\u304f\u3089\u3044\u306e\u6642\u9593\u306fUITableView\u306b\u8cbb\u3084\u3057\u3066\u3044\u308b\u6c17\u304c\u3057\u3066\u304d\u307e\u3059\u3002 UIT [&hellip;]<\/p>\n","protected":false},"author":128,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[54,39],"class_list":["post-9669","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-advent-calendar","tag-ios"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/9669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/128"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=9669"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/9669\/revisions"}],"predecessor-version":[{"id":9748,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/9669\/revisions\/9748"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=9669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=9669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=9669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}