导航控制器中的IOS表视图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导航控制器中的IOS表视图相关的知识,希望对你有一定的参考价值。

Pulls data from a plist set up as a dictionary of arrays of strings.
Creates multi-level TableView that can be nested inside a navigation controller.
Snippet shows key methods for 2 nested levels.
2 levels --> 2 classes (both of which extend UITableViewController)
  1. // ---------- Top Level ----------------
  2. - (void)viewDidLoad {
  3.  
  4. self.title = @"Categories";
  5. NSMutableArray *array = [[NSMutableArray alloc] init];
  6.  
  7. NSString *path = [[NSBundle mainBundle] pathForResource:@"CategoryData"
  8. ofType:@"plist"];
  9. NSDictionary *dict = [[NSDictionary alloc]
  10. initWithContentsOfFile:path];
  11. self.buildings = dict;
  12. [dict release];
  13.  
  14. for(id name in buildings) {
  15. CategorySecondLevelViewController *controller = [[CategorySecondLevelViewController alloc]
  16. initWithStyle:UITableViewStylePlain];
  17. controller.title = name;
  18.  
  19. [array addObject:controller];
  20. [controller release];
  21. }
  22.  
  23. self.categories = array;
  24. [array release];
  25.  
  26. [super viewDidLoad];
  27. }
  28.  
  29. - (UITableViewCell *)tableView:(UITableView *)tableView
  30. cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  31.  
  32. static NSString *CategoryCell = @"CategoryCell";
  33.  
  34. // reuse cell if possible
  35. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
  36. CategoryCell];
  37. if(cell == nil) {
  38. cell = [[[UITableViewCell alloc]
  39. initWithStyle: UITableViewCellStyleDefault
  40. reuseIdentifier: CategoryCell] autorelease];
  41. }
  42.  
  43. // configure cell
  44. NSUInteger row = [indexPath row];
  45.  
  46. // extension point to include images if wanted
  47. UITableViewController *controller = [categories objectAtIndex:row];
  48. cell.textLabel.text = controller.title;
  49. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  50. return cell;
  51. }
  52.  
  53. // ---------- Second Level ----------------
  54. - (void)viewDidLoad {
  55.  
  56. NSString *path = [[NSBundle mainBundle] pathForResource:@"CategoryData"
  57. ofType:@"plist"];
  58. NSDictionary *dict = [[NSDictionary alloc]
  59. initWithContentsOfFile:path];
  60.  
  61. NSString *key = self.title;
  62. NSArray *values = [dict objectForKey:key];
  63.  
  64. self.list = values;
  65. [dict release];
  66.  
  67. [super viewDidLoad];
  68. }
  69.  
  70. - (UITableViewCell *)tableView:(UITableView *)tableView
  71. cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  72.  
  73. static NSString *BuildingIdentifier = @"BuildingIdentifier";
  74. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
  75. BuildingIdentifier];
  76. if(cell == nil) {
  77. cell = [[[UITableViewCell alloc]
  78. initWithStyle:UITableViewCellStyleDefault
  79. reuseIdentifier:BuildingIdentifier] autorelease];
  80. }
  81.  
  82. NSUInteger row = [indexPath row];
  83. cell.textLabel.text = [list objectAtIndex:row];
  84.  
  85. return cell;
  86. }

以上是关于导航控制器中的IOS表视图的主要内容,如果未能解决你的问题,请参考以下文章

底部导航视图中的每个选项卡单击都会重新加载片段

iOS - 故事板中的导航控制器

从视图控制器呈现导航视图 - IOS 7

当我点击导航栏时,来自栏按钮的 ios 操作表不会关闭

我在应用程序加载而不是图像时开发启动视频。并且​​还使用 ios 中的推送视图控制器导航到下一页

IOS - 从表视图控制器获取值并将其发送到另一个表视图控制器