你想住哪?

一,创建第二个界面 , 继承于ViewController
ViewController.m 代码为

#import "ViewController.h"
#import "twoViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *oneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 414, 714)];
    UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 414, 200)];
    imgV.image = [UIImage imageNamed:@"Snip20180818_1"];
    [oneView addSubview:imgV];
    [self.view addSubview:oneView];
    UISearchBar *sec = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 180, 394, 60)];
    sec.backgroundColor = [UIColor whiteColor];
    sec.placeholder = @"您想在哪住?";
    sec.layer.cornerRadius = 10;
    sec.layer.masksToBounds = YES;
    UITapGestureRecognizer *tag = [[UITapGestureRecognizer alloc] init];
    [oneView addGestureRecognizer:tag];
    [tag addTarget:self action:@selector(add)];
    [oneView addSubview:sec];
    UIImageView *centerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 250, 414, 100)];
    centerView.image = [UIImage imageNamed:@"Snip20180818_2"];
    [oneView addSubview:centerView];
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 360, 414,(714-320)) style:UITableViewStyleGrouped];
    table.delegate = self;
    table.dataSource= self;
    [oneView addSubview:table];
}
-(void)add{
    twoViewController *two = [[twoViewController alloc] init];
    [self presentViewController:two animated:YES completion:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    tableView.rowHeight = 150;
    if (indexPath.section ==0) {
        UIImageView *imgV =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 414, 150)];
        imgV.image = [UIImage imageNamed:@"Snip20180818_3"];
        [cell addSubview:imgV];
    }else{

    }
    return cell;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return @"便宜优选";
    }else{
        return @"居住升级";
    }
}
@end

第二界面 .m 代码为

#import "twoViewController.h"

@interface twoViewController ()

@end

@implementation twoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UISearchBar *sec = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 414, 60)];
    [self.view addSubview:sec];
    UIImageView *imgv =[[UIImageView alloc] initWithFrame:CGRectMake(0, 60, 414, (714-60))];
    imgv.image = [UIImage imageNamed:@"Snip20180818_4"];
    [self.view addSubview:imgv];
}
@end

猜你喜欢

转载自blog.csdn.net/weixin_42925415/article/details/81806834