标签:animate 省份 河北 ctr button ima selectrow dip ati
code2: * - (IBAction)popOver:(id)sender { AddressViewController *contentVC = [[AddressViewController alloc] init]; contentVC.modalPresentationStyle = UIModalPresentationPopover; contentVC.popoverPresentationController.sourceView = self.view; contentVC.popoverPresentationController.sourceRect = CGRectMake(100, 100, 100, 100); contentVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp; [self presentViewController:contentVC animated:YES completion:nil]; } * AddressViewController.m * #import "AddressViewController.h" @interface AddressViewController () <UITableViewDelegate, UITableViewDataSource> @property (weak, nonatomic) IBOutlet UITableView *masterTableView; // 省份tableView @property (weak, nonatomic) IBOutlet UITableView *detailTableView; // 地区tableView @property (nonatomic, strong) NSArray *masterDataSource; // 省份数据源 @property (nonatomic, strong) NSArray *detailDataSource; // 地区数据源 @property (nonatomic, assign) int masterIndex; // 选中的省份 @end @implementation AddressViewController - (void)viewDidLoad { [super viewDidLoad]; _masterIndex = 0; self.preferredContentSize = CGSizeMake(150, 300); } - (NSArray *)masterDataSource { if (_masterDataSource == nil) { _masterDataSource = @[@"河南", @"河北", @"江苏", @"浙江", @"广东"]; } return _masterDataSource; } - (NSArray *)detailDataSource { if (_detailDataSource == nil) { _detailDataSource = @[@[@"郑州", @"洛阳", @"周口", @"开封"], @[@"石家庄", @"石家庄2"], @[@"南京", @"苏州", @"淮安", @"淮北", @"句容"], @[@"杭州", @"温州", @"台州", @"宁波", @"瑞安", @"苍南"], @[@"广州", @"深圳"] ]; } return _detailDataSource; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.masterTableView) { return self.masterDataSource.count; } if (tableView == self.detailTableView) { return [self.detailDataSource[_masterIndex] count]; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == self.masterTableView) { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"master"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"master"]; } cell.textLabel.text = self.masterDataSource[indexPath.row]; return cell; } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detail"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"detail"]; } cell.textLabel.text = self.detailDataSource[_masterIndex][indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == _masterTableView) { _masterIndex = (int)indexPath.row; self.preferredContentSize = CGSizeMake(300, 300); [_detailTableView reloadData]; } if (tableView == _detailTableView) { self.preferredContentSize = CGSizeMake(150, 300); [_detailTableView reloadData]; } } @end
iPad 控件 UIPopoverPresentationController 使用 iPhone可用
标签:animate 省份 河北 ctr button ima selectrow dip ati
原文地址:http://www.cnblogs.com/10-19-92/p/6215849.html