iOS-UIPopoverController(ipad)

UIPopoverController只能在ipad设备上面使用;作用是用于显示临时内容,特点是总是显示在当前视图最前端,有一个箭头可以指示从哪一个button弹出来的,,当单击界面的其他地方时自动消失。

(1)创建两个UIViewController类(ListViewController和oneViewController)

ListViewController作为一个弹出的控制器视图显示

(2)建好弹出视图显示些什么,就是弹出一个表。

[objc]

#import <UIKit/UIKit.h>

@interface ListViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>

@property (strong,nonatomic)UITableView *favoriteTableView;//收藏夹table view

@property (strong,nonatomic)NSMutableArray *list;//收藏夹list

@end

[objc]

#import "ListViewController.h"

#import "threeViewController.h"

@interface ListViewController ()

@end

@implementation ListViewController

– (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

return self;

}

– (void)viewDidLoad

{

[super viewDidLoad];

self.list = [[NSMutableArray alloc] initWithObjects:@"willingseal",@"?viewmode=contents",@"有些事不是因为看到了希望才去坚持,而是坚持了才会看到了希望",@"爱情はひとりの诈欺师に恋をしていた馬鹿な童话…バカ愛情はひとりの詐欺師に恋をしていた馬鹿な童話", nil nil];

[self addTableview];

}

– (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

//初始化table view

-(void) addTableview {

self.favoriteTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 400,500) style:UITableViewStylePlain];//初始化tabview

// self.favoriteTableView.center =CGPointMake(self.view.center.x, self.view.center.y-70);//tableview的中心位置

self.favoriteTableView.delegate = self;

self.favoriteTableView.dataSource=self;

self.favoriteTableView.scrollEnabled=YES;//tabview是否滑动

// self.favoriteTableView.layer.cornerRadius=15;//圆角大小

// _loginTableView = TableView;

self.favoriteTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];

[self.view addSubview:self.favoriteTableView];

}

#pragma mark – Table view data source

//行高

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 50;

}

//多少个section

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}

//section里面有多少行

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex

{

NSLog(@"list is :%lu",[self.list count]);

return [self.list count];;

}

//cell内容

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *CellIdentifier = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell ==nil) {

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

NSInteger row = [indexPath row];

cell.textLabel.text = [self.list objectAtIndex:row];

return cell;

}

//点击某个table view cell

– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

NSString * selectStr =[[NSString alloc] initWithFormat:@"%@",[self.list objectAtIndex:indexPath.row]];

NSLog(@"%@",[self.list objectAtIndex:indexPath.row]);

只有一条路不能选择——那就是放弃的路;

iOS-UIPopoverController(ipad)

相关文章:

你感兴趣的文章:

标签云: