Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UITableVIewの中身を分割してみませんか?

0d04162c7a3c2907c059a06dbcd23cf4?s=47 tokorom
February 13, 2014

 UITableVIewの中身を分割してみませんか?

UITableViewの中身をUIViewControllerで分割する方法と、DataSource/Delegateだけを分割する方法のメリット/デメリット

0d04162c7a3c2907c059a06dbcd23cf4?s=128

tokorom

February 13, 2014
Tweet

More Decks by tokorom

Other Decks in Technology

Transcript

  1. UITableViewͷத਎Λ ෼ׂͯ͠Έ·ͤΜ͔ʁ ॴ ༑ଠ @tokorom iOS App Programer These are

    “not” confidential sessions—please diffuse by your blogging and twitter potatotips #4
  2. Α͋͘Δ͜͏͍͏ը໘ͷ࣮૷ ϐοΫΞοϓ ࠷৽ Φεεϝ

  3. ౖᔶͷSwitchจ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row

    = indexPath.row; NSUInteger section = indexPath.section; switch (section) { case MMSectionXXX: { MMXXXCell *cell = (MMXXXCell *)[self.tableView dequeueReusableCellWithIdentifier:@"MMXXXCell"]; if (nil == cell) { cell = [[MMXXXCell alloc] initWithReuseIdentifier:@"MMXXXCell"]; } cell.xxx = yyy; ɹɹɹɹɹ } break; case MMSectionYYY: case MMSectionZZZ:
  4. ౖᔶͷ௨৴ϦΫΤετͱදࣔ -ϐοΫΞοϓίϯςϯπΛऔಘͯ͠දࣔ -৽ணίϯςϯπΛऔಘͯ͠දࣔ -ΦεεϝίϯςϯπΛऔಘͯ͠දࣔ

  5. ίϯςϯπ͝ͱʹControllerΛ ෼͚͍ͨΑͶ

  6. ViewControllerΛ෼͚Δ UIViewController UIViewController UIViewController

  7. ϝϦοτ -࢖͍׳ΕͨViewControllerΛ࢖͑Δ -൚༻ੑ͕ߴ͍

  8. σϝϦοτ -Ωϟογϡͷ࢓૊Έ͕࢖͍ͮΒ͍ -දࣔ͞Ε͍ͯͳ͍෦෼ͷίϯςϯπ΋औಘ͠ͳ͚Ε ͹ͳΒͳ͍ʢ͜ͱ͕͋Δʣ -TableView in TableView ͷϦεΫ͕͋Δʁ

  9. DataSource/DelegateΛ෼͚Δ DataSource 1 DataSource 2 DataSource 3

  10. ֤ηΫγϣϯͷControllerʹॲཧΛৼΓ௚͢ section 1 x row 1 section 1 x row

    3 section 1 x row 3
  11. ϝϦοτ -ηΫγϣϯΛ·͍ͨͰΩϟογϡ͕ར༻Ͱ͖Δ -;ͭ͏ͷTableViewͷ࢖͍ํͳͷͰϦεΫ͕গͳ͍

  12. σϝϦοτ -֤ηΫγϣϯʢControllerʣʹৼΓ෼͚Δͷ͕໘ ౗͍͘͞

  13. https://github.com/tokorom/ TKRContainerTableViewController

  14. ϝΠϯͷViewController - (void)viewDidLoad { [super viewDidLoad]; ! [self addController:[PickupController new]];

    [self addController:[ListController new]]; [self addController:[ListController new]]; }
  15. ֤ηΫγϣϯͷController - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell

    = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; cell.textLabel.text = [NSString stringWithFormat:@"list %d", indexPath.row]; cell.imageView.image = [UIImage imageNamed:@"Dog"]; return cell; }
  16. ·ͱΊ -̍ͭͷViewController಺Ͱ͍ΖΜͳίϯςϯπΛ ѻ͏ͷ͸ࢭΊΑ͏ -ίϯςϯπ͕ݶఆతͳ৔߹ʹ͸ηΫγϣϯ͝ͱʹ addChildViewControllerΛ෼͚Δͷ΋༗༻ -ࠓͷͱ͜ΖDataSource/DelegateΛ෼ׂ֤ͯ͠ ControllerʹৼΓ෼͚Δͷ͕҆શʁ

  17. More Information Yuta ToKoRo! iOS App Programer! @tokorom! ! http://www.tokoro.me/

    https://github.com/tokorom/TKRContainerTableViewController