学习制作iOS程序第六天:我的页面-主页面(19)

十九、我的页面 - 主页面

刚完成了首页推荐二手房这个很麻烦的东西,来点轻松的吧。先做后台我的页面把。

第一版不涉及到客户的登录注册操作,所以相对来说比较简单一点。主要是系统自带的tableview的使用。

也是因为没有客户的登录等操作,所以一些查看记录是保存在本地的。如果卸载了app再重新安装是为空的。

1、.h文件创建变量

#import <UIKit/UIKit.h>

@interface RDMyTableViewController : UIViewController

@property(nonatomic,strong) UITableView *tableView;
@property(strong,nonatomic) UIImageView *zoomImageView;

@end

2、m文件之tableview

(1)定义数据变量并加载delegate

@interface RDMyTableViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray *arrList;
}
@end

(2)tableview初始化

    //初始化我的信息
    arrList =
@[
    @[
        [NSMutableDictionary dictionaryWithObjectsAndKeys:@"我看过的房源",@"title",@"icon_viewhistory",@"image",@"1",@"isshow",nil],
        [NSMutableDictionary dictionaryWithObjectsAndKeys:@"我关注的新房",@"title",@"icon_focus_house",@"image",@"1",@"isshow",nil],
        [NSMutableDictionary dictionaryWithObjectsAndKeys:@"我关注的二手房/租房",@"title",@"icon_focus_house",@"image",@"1",@"isshow",nil]
    ],@[
        [NSMutableDictionary dictionaryWithObjectsAndKeys:@"购房计算器",@"title",@"icon_jisuanqi",@"image",@"1",@"isshow",nil]
    ],@[
        [NSMutableDictionary dictionaryWithObjectsAndKeys:@"设置",@"title",@"icon_setup",@"image",@"1",@"isshow",nil],
    ]
];

    //初始化tableview
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height+20, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate=self;
    self.tableView.dataSource = self;
    self.tableView.contentInset = UIEdgeInsetsMake(BGIMAGEHEIGHT, 0, 0, 0);
    self.tableView.rowHeight=46.0f;
    [self.view addSubview:self.tableView];

    //定义复用的cell
    [self.tableView registerClass:[SetupListCell class] forCellReuseIdentifier:@"setuplistcell"];

(3)tableview的委托方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return arrList.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *arrSection = arrList[section];
    return arrSection.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setuplistcell" forIndexPath:indexPath];
    NSArray *arrSection = arrList[indexPath.section];
    NSDictionary *dictData = arrSection[indexPath.row];

    cell.textLabel.text = [dictData objectForKey:@"title"];
    cell.imageView.image=[UIImage imageNamed:[dictData objectForKey:@"image"]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10.0f;
}

(4)tableview单元格点击事件 部分函数待实现

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if(indexPath.section==0)
    {
        if (indexPath.row==0) {
            #warning 待定代码 我看过的房源
            //我看过的房源
        }else if (indexPath.row==1)
        {
            #warning 待定代码 我关注的新房
            //我关注的新房
        }else if (indexPath.row==2)
        {
            #warning 待定代码 我关注的二手房
            //我关注的二手房
        }

    }else if(indexPath.section==1)
    {
        if (indexPath.row==0) {
            #warning 待定代码 房贷计算器
            //房贷计算器
        }
    }else if(indexPath.section==2)
    {
        if (indexPath.row==0) {
            //设置
            RDSetupViewController *setupvc = [[RDSetupViewController alloc]init];
            self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];
            [self.navigationController pushViewController:setupvc animated:NO];
        }
    }
}

(5)uitableviewcell没有用默认的系统cell,稍微做了一点改动,名字是SetupListCell

#import "SetupListCell.h"

@implementation SetupListCell

- (void)awakeFromNib {
    // Initialization code
}

//重写layoutSubviews方法,以便实现图片大小效果
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame=CGRectMake(15, (self.frame.size.height-20)/2, 20, 20);
    self.imageView.contentMode=UIViewContentModeScaleAspectFit;
    CGRect tempframe = self.textLabel.frame;
    tempframe.origin.x=50;
    self.textLabel.frame=tempframe;
    self.textLabel.font=[UIFont systemFontOfSize:14];
    self.separatorInset=UIEdgeInsetsMake(0, 50, 0, 0);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

3、.m文件之下拉放大图。

(1)定义宏变量

#define BGIMAGEHEIGHT 160.0f

(2)初始化图片view

    //初始化缩放图片
    self.zoomImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -BGIMAGEHEIGHT, SCREEN_WIDTH, BGIMAGEHEIGHT)];
    self.zoomImageView.image = [UIImage imageNamed:@"main_my_bg"];
    self.zoomImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.tableView addSubview:_zoomImageView];

(3)scroll触发方法

#pragma mark scrollview滚动事件
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //当滚动的时候缩放图片
    CGFloat y = self.tableView.contentOffset.y;
    if (y<=BGIMAGEHEIGHT)
    {
        CGRect frame=_zoomImageView.frame;
        frame.origin.y = y;
        frame.size.height = -y;
        _zoomImageView.frame = frame;
    }

}

看看效果。

时间: 2025-01-13 20:04:31

学习制作iOS程序第六天:我的页面-主页面(19)的相关文章

学习制作iOS程序第三天:创建全局变量,预编译函数等、优化TabBarController、加入Bugly崩溃日志、解决键盘覆盖文本框的问题

十一:创建Define定义文件和pch预处理文件 1.在Define目录里创建Const.h文件,用于保存一些常用的宏命令 #define CURRENT_APPID @"" #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define IS_

学习制作iOS程序第二天:创建子目录、更改项目名称、修改启动画面、修改类前缀、新建启动控制器、修改APP图标

四.根据实际情况创建相应的目录 删除系统默认的部分文件ViewController.h,ViewController.m,Main.storyboard.LaunchScreen.xib 目录根据情况创建,每个人都会不一样的.我的如下. 五:更改项目名称 1.进入项目的Targets属性,找到Build Settings,搜索Product Name,修改属性为真实的软件名称. 2.打开Supporting Files目录下的Info.plist,修改Bundle name为真实的软件名称. 3

学习制作iOS程序第一天:建立主目录、源代码管理、Pod安装第三方组件

前言 俗话说,看过的能记住20%,用过的能记住40%,解决过错误的能记住60%,为此加班好几天解决问题的能记住80%.利用自学的iOS知识搭建一个中介查房的软件.学以致用. 一.建立文件目录 打开XCode,新建一个“Single View Application”.保存到桌面新建的目录“randy.company.customerappios”里,本文只考虑iOS7.0及以上,以下的暂不考虑了. 二.连接到git服务器(Bitbucket) 1.进入Bitbucket后台管理,新建一个repo

iOS学习笔记---c语言第六天

函数  function 命名规范:工程名第一个字母大写,变量函数名小写,不要用拼音和中文, eg:lessonFunction 一.函数声明定义 函数是具有特定功能的代码块        作用:模块化程序 用函数的好处:简化程序.提高开发效率.方便阅读和修改等 函数定义: 返回值类型  函数名(形式参数) { 语句 return 返回值: }     返回值类型:viod  int  char float.....    void下面可以不写return    ,int  下面返回值为整型,c

《iOS应用逆向工程》学习笔记(四)iOS程序类型

越狱iOS中最常见的程序有Application, Dynamic Library和Daemon三类. 1.Application 除了传统意义上的App外,越狱iOS平台上还有两种App形式的存在:WeeApp(依附于NotificationCenter的App)和PreferenceBundle(依附于Settings的App),常见于Cydia平台. 普通App的bundle中存放的是可执行程序和所需资源,而framework的bundle中存放的是动态链接库. 主要关注App中的三个部分

学习制作手机页面2

学习制作手机页面2. 先介绍一个css3的属性.box-sizing 这个属性 就是把盒模型的border 和padding 都计算在内 未使用box-sizing的代码 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>box-sizing</title> 6 7 <style&

ios学习-delegate、传值、跳转页面

ios学习-delegate.传值.跳转页面 1.打开xcode,然后选择ios--Application--Empty Application一个空项目. 项目目录: 2.输入项目名称以及选择保存路径即可. 3.创建文件夹Model.Controller. 4.Model文件夹创建User类:User.h User.m 代码: User.h: [html] view plaincopy #import <Foundation/Foundation.h> @interface User : N

iOS学习笔记---oc语言第六天

Block .数组高级 block本质上就是匿名函数(没有名称的函数) block语法和函数指针很相似 回顾函数 函数:C语?中,实现某一类功能的代码段. 完整的函数包含两部分:函数声明.函数定义 函数声明,即函数原型.例如:int sum(int x,int y);具有两个整型参 数,一个整型返回值的函数. 函数定义,即函数实现.例如:int sum(int x,int y){     retrun x + y;     } 回顾函数指针 函数指针(变量):存放函数地址(函数名)的指针变量.

【学习总结】IOS程序运行过程 、UIWindow 、controller 、 UIView 创建过程的总结

程序启动开始到view显示: 程序启动首先会执行main函数 - > UIApplicationMain函数: 程序启动 (加载框架,info文件,资源等) 执行Main函数 初始化UIApplication单例对象 初始化AppDelegate对象,并设为UIApplication对象的代理 然后调用UIApplication的didFinishLaunchingWithOptions方法创建UIWindow对象,设置rootViewController根控制器等 然后建立一个主事件循环,其中