SBSelectPropertyViewController.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // SBSelectPropertyViewController.m
  3. // JDStatusBarNotificationExample
  4. //
  5. // Created by Markus Emrich on 09.11.13.
  6. // Copyright (c) 2013 Markus. All rights reserved.
  7. //
  8. #import "SBSelectPropertyViewController.h"
  9. @interface SBSelectPropertyViewController ()
  10. @property (nonatomic, strong) NSArray *data;
  11. @property (nonatomic, copy) SBSelectPropertyResultBlock resultBlock;
  12. @end
  13. @implementation SBSelectPropertyViewController
  14. - (id)initWithData:(NSArray*)data
  15. resultBlock:(SBSelectPropertyResultBlock)resultBlock;
  16. {
  17. self = [super initWithStyle:UITableViewStylePlain];
  18. if (self) {
  19. self.data = data;
  20. self.resultBlock = resultBlock;
  21. self.activeRow = -1;
  22. }
  23. return self;
  24. }
  25. #pragma mark - Table view data source
  26. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  27. {
  28. return 1;
  29. }
  30. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  31. {
  32. return self.data.count;
  33. }
  34. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  35. {
  36. // create / dequeue cell
  37. static NSString* identifier = @"identifier";
  38. UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  39. if (cell == nil) {
  40. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  41. cell.textLabel.font = [UIFont systemFontOfSize:14.0];
  42. }
  43. cell.textLabel.text = self.data[indexPath.row];
  44. if (indexPath.row == self.activeRow) {
  45. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  46. } else {
  47. cell.accessoryType = UITableViewCellAccessoryNone;
  48. }
  49. return cell;
  50. }
  51. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
  52. {
  53. if (self.resultBlock) {
  54. self.resultBlock(indexPath.row);
  55. }
  56. }
  57. @end