专业java、php、iOS、C++、网页设计、平面设计、网络营销、游戏开发、前端与移动开发培训机构
分类控制器
在
CZPictureWallViewController
的categoryTopItemClick
使用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 Owner
为CZCategoryViewController
将
mainTableView
和subTableView
连接到CZCategoryViewController
, 设置mainTableView
和subTableView
的数据源和代理为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
- 运行效果如下: