iOS笔记UI--ipad分页控件

声明:此为本人学习笔记,若有纰漏错误之处的可留言共同探讨

/* 思路
1 左边是一个VC,加入tableView作为标签,右边也是一个VC,加入WebView显示要加载的内容
2 在设置监听中心 监听左边  ,左边的cell选中时发送通知,右边接到消息即解析url到webView  具体参考下面代码
注意
操作的时候记得把屏幕横向过来 */

左边

#import "ViewController.h"
NSString *const WebURL = @"WebURL";
NSString *const WebURLNSNotificationCenter = @"WebURLNSNotificationCenter";
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSDictionary *dataDic;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    dataDic = [NSDictionary dictionaryWithObjectsAndKeys:@"http://www.baidu.com",@"百度",@"http://www.qq.com",@"腾讯",@"http://www.163.com",@"网易", nil];
    UITableView *useTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    useTable.delegate = self;
    useTable.dataSource =self;
    [self.view addSubview:useTable];
}


#pragma mark - 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  dataDic.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell ==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }
    
    NSLog(@"%@",dataDic);
    NSArray *AllKey = [dataDic allKeys];
    NSArray *AllValue = [dataDic allValues];
    cell.textLabel.text = AllKey[indexPath.row];
    cell.detailTextLabel.text = AllValue[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    NSArray *values = [dataDic allValues];
    NSArray *mark = values[indexPath.row];
    
    NSDictionary *userinfo = @{WebURL:mark};
    [center postNotificationName:WebURLNSNotificationCenter object:nil userInfo:userinfo];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

右边

#import "RootViewController.h"

@interface RootViewController ()
{
    UIWebView *webView;
}
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
     webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
    [webView loadRequest:request];
    
    webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    
    
    // 监听左边视图控制器发送的消息
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(changeURL:) name:@"WebURLNSNotificationCenter" object:nil];
    [self.view addSubview:webView];
    // Do any additional setup after loading the view.
}


-(void)changeURL:(NSNotification*)center
{
    NSLog(@"%@",center.userInfo);
    NSString *url = center.userInfo[@"WebURL"];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    [webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end


附上代码:http://download.csdn.net/detail/csdn_hhg/9261579
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值