专业java、php、iOS、C++、网页设计、平面设计、网络营销、游戏开发、前端与移动开发培训机构

分类控制器

  • CZPictureWallViewControllercategoryTopItemClick 使用 UIPopoverController 弹出 CZCategoryViewController

      #pragma mark - 按钮点击代理
      - (void)categoryTopItemClick {
          CZLog(@"categoryTopItemClick");
    
          CZCategoryViewController *categoryVC = [[CZCategoryViewController alloc] init];
    
          UIPopoverController *categoryPopover = [[UIPopoverController alloc] initWithContentViewController:categoryVC];
    
          [categoryPopover presentPopoverFromBarButtonItem:self.categoryItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
      }
    
  • CZCategoryViewController 使用 xib 来布局
  • 回顾xib加载流程
  • CZCategoryViewController.xib 来布局界面
  • 设置 File's OwnerCZCategoryViewController
  • mainTableViewsubTableView 连接到 CZCategoryViewController, 设置 mainTableViewsubTableView 的数据源和代理为 CZCategoryViewController

      @interface CZCategoryViewController () <UITableViewDataSource, UITableViewDelegate>
      @property (weak, nonatomic) IBOutlet UITableView *mainTableView;
    
      @property (weak, nonatomic) IBOutlet UITableView *subTableView;
      @end
    
  • CZCategoryViewController 显示内容

      @implementation CZCategoryViewController
    
      - (void)viewDidLoad {
          [super viewDidLoad];
    
          self.preferredContentSize = CGSizeMake(400, 400);
    
          [self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:mainCellIdentifier];
    
          [self.subTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:subCellIdentifier];
      }
    
      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
          return 20;
      }
    
      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
          if (tableView == self.mainTableView) {
              UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mainCellIdentifier forIndexPath:indexPath];
    
              cell.textLabel.text = @"main";
    
              return cell;
          } else {
              UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:subCellIdentifier forIndexPath:indexPath];
    
              cell.textLabel.text = @"sub";
    
              return cell;
          }
      }
      @end
    
  • 运行效果如下: