IOS项目之 爱限免一

项目创建

1、获取项目所需的相关素材,界面效果图,界面的素材,以及拿到网络接口等。

2、创建项目,项目中创建一些逻辑文件夹,用来存放相应的文件,清晰的展示

引入AFNetworking;

3、各个ViewController的设计,设计多个界面分别展示。

#import "RootViewController.h"
#import "ApplistViewController.h"
#import "HotViewController.h"
#import "ScaleViewController.h"
#import "TopicViewController.h"
#import "FreeViewController.h"
#import "LimitViewController.h"

4.创建RootViewController的导航栏以及标签栏(此过程中进行了封装)

4.1 继承UIImageView 的类别创建,便于后期创建多个button,或者多个Label

//添加系统按钮
-(UIButton *) addSystemButtonWithFrame: (CGRect )frame title:(NSString *)title action:(void (^)(UIButton *button))action{
    JayzyButton *button =[JayzyButton buttonWithType:UIButtonTypeSystem];
    button.frame =frame;
    [button setTitle:title forState:UIControlStateReserved];

    button.action =action;
    [self addSubview:button];
    return button;
}
//添加图片按钮
-(UIButton *) addImageButtonWithFrame: (CGRect )frame title:(NSString *)title background:(NSString *) background action:(void (^)(UIButton *button))action{

    JayzyButton *button =[JayzyButton buttonWithType:UIButtonTypeSystem];
    button.frame =frame;
    [button setTitle:title forState:UIControlStateReserved];
    [button setBackgroundImage:[UIImage imageNamed:background] forState:UIControlStateNormal];
    button.action =action;
    [self addSubview:button];
    return button;

}

//添加imageView
-(UIImageView*) addImageViewWithFrame: (CGRect )frame image:(NSString *)image{
    UIImageView *imageView =[[UIImageView alloc] initWithFrame:frame];
    imageView.image =[UIImage imageNamed:image];
    imageView.userInteractionEnabled =YES;
    [self addSubview:imageView];
    return imageView;

}
//添加标签
-(UILabel *) addLabelWithFrame: (CGRect )frame text:(NSString *)text{
    UILabel *label =[[UILabel alloc] initWithFrame:frame];
    label.text =text;
    [self addSubview:label];
    return label;
}

4.2 需要创建5个视图由标签控制器控制,统一进行封装,传入类别,标签Title,标签背景图片

//快速添加一个试图控制器
-(UIViewController *) addViewController:(Class)cls title :(NSString *)title image: (NSString *) image
{
 //cls 传入界面所对应的类
    UIViewController *vc =[[cls alloc] init];
    vc.title =title;
    UINavigationController *nc =[[UINavigationController alloc] initWithRootViewController:vc];
    nc.tabBarItem.image =[UIImage imageNamed:image];

    //添加到标签中
    NSMutableArray *marr =[[NSMutableArray alloc] initWithArray:self.viewControllers];
    [marr addObject:nc];
    self.viewControllers =marr;
//返回创建的试图控制器
    return vc;

}

4.3 开始设置首页导航栏的左右按钮

  [self configNavigationButton];

#pragma mark ------配置导航条
-(void)configNavigationButton
{
//要创建多个button的时候,要设置多个视图
    UIButton *leftButton =[UIButton buttonWithType:UIButtonTypeSystem];
    leftButton.frame =CGRectMake(0, 0, 45, 30);
    [leftButton setTitle:@"分类" forState:UIControlStateNormal];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"buttonbar_action.png"] forState:UIControlStateNormal];
[leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    leftButton.titleLabel.font =[UIFont systemFontOfSize:14.0f];
    [leftButton addTarget:self action:@selector(dealleftClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem =[[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem =leftItem;
    //添加右导航
    UIButton *rightButton =[UIButton buttonWithType:UIButtonTypeSystem];
    rightButton.frame =CGRectMake(0, 0, 45, 30);
    [rightButton setTitle:@"设置" forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightButton setBackgroundImage:[UIImage imageNamed:@"buttonbar_action.png"] forState:UIControlStateNormal];
    rightButton.titleLabel.font =[UIFont systemFontOfSize:14.0f];
    [rightButton addTarget:self action:@selector(dealrightClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem =[[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem =rightItem;
}

4.4下载数据进行解析,配置页面的UITableView

_dataArray=[[NSMutableArray alloc] init];
    _page =1;
    _categoryId =@"";//URL接口中" "表示全部
    [self startDownloadData];
============ ===============
-(void)startDownloadData
{
    //下载数据,JSON的解析
    NSString *urlString =[NSString stringWithFormat:LIMIT_URL,_page,_categoryId];
    AFHTTPRequestOperationManager *manager =[AFHTTPRequestOperationManager manager];
    manager.responseSerializer =[AFHTTPResponseSerializer serializer];
    [manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //进行JSON格式的解析
        NSDictionary *dict =[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"dict = %@",dict);
        NSArray *appList = dict[@"applications"];
        for(NSDictionary *appDict in appList){
           //这里先创建数据模型model
            [self creatModelCodeWithDictionary:appDict name:@"AppModel"];
           //kvc,如果键值没有对应的属性,会崩溃。
            AppModel *model =[[AppModel alloc] init];
            [model setValuesForKeysWithDictionary:appDict];
             model.desc =appDict[@"description"];
            [_dataArray addObject:model];
        }
         [_tableView reloadData];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];

}

4.5 根据下载的数据分析,创建数据模型。

//创建model的代码,根据字典生成代码
-(void)creatModelCodeWithDictionary:(NSDictionary *)dict name :(NSString *)name
{
    printf("\[email protected] %s:NSObject\n",name.UTF8String);
    for(NSString *key in dict){

        printf("@property(copy,nonatomic) NSString *%s;\n",key.UTF8String);
    }
    printf("@end\n");
}
============================================

@interface AppModel:NSObject
@property(copy,nonatomic) NSString *priceTrend;
@property(copy,nonatomic) NSString *expireDatetime;
@property(copy,nonatomic) NSString *fileSize;
@property(copy,nonatomic) NSString *categoryName;
@property(copy,nonatomic) NSString *ipa;
@property(copy,nonatomic) NSString *itunesUrl;
@property(copy,nonatomic) NSString *name;
@property(copy,nonatomic) NSString *version;
@property(copy,nonatomic) NSString *currentPrice;
@property(copy,nonatomic) NSString *starCurrent;
@property(copy,nonatomic) NSString *starOverall;
@property(copy,nonatomic) NSString *favorites;
@property(copy,nonatomic) NSString *iconUrl;
@property(copy,nonatomic) NSString *releaseNotes;
@property(copy,nonatomic) NSString *releaseDate;
@property(copy,nonatomic) NSString *updateDate;
@property(copy,nonatomic) NSString *slug;
@property(copy,nonatomic) NSString *downloads;
@property(copy,nonatomic) NSString *lastPrice;
@property(copy,nonatomic) NSString *ratingOverall;
@property(copy,nonatomic) NSString *applicationId;
@property(copy,nonatomic) NSString *desc;//改成了

@property(copy,nonatomic) NSNumber *categoryId;//修改
@property(copy,nonatomic) NSString *shares;//修改
@end

4.6 创建UITableView ,展示数据

#pragma mark ---表格视图显示数据
-(void)createTableView
{

    _tableView  =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.dataSource=self;
    _tableView.delegate =self;
    [self.view addSubview:_tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *cellID =@"cell";
    AppCell *cell =[tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell ==nil) {
        cell =[[AppCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
    }
    AppModel *model =_dataArray[indexPath.row];
//    cell.textLabel.text =model.name;
    [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.iconUrl]];
//    cell.nameLable.text =model.name;
    cell.nameLable.text =[NSString stringWithFormat:@"%d.%@",indexPath.row+1,model.name];

//    cell.priceLabel.text =model.lastPrice;
    cell.priceLabel.text =[NSString stringWithFormat:@"¥%.2f",model.lastPrice.doubleValue];
    cell.categoryLabel.text =model.categoryName;
    [cell.starView setStar:model.starCurrent.doubleValue];
    cell.shareLabel.text =[NSString stringWithFormat:@"分享:%d",model.shares.intValue];
    cell.favoriteLabel.text =[NSString stringWithFormat:@"收藏:%d",model.favorites.intValue];
    cell.downloadLabel.text =[NSString stringWithFormat:@"下载:%d",model.downloads.intValue];
    return cell;

}
时间: 2024-12-21 18:56:10

IOS项目之 爱限免一的相关文章

iOS项目生成通用Windows应用

WinObjc - 使用iOS项目生成通用Windows应用 Github上一周年的WinObjc项目最近发布了预览版本,终于等到了这一天.WinObjc项目就是Build 2015大会上微软宣布的Project IslandWood项目,致力于将iOS应用快速移植成UWP应用.废话不多说,让我们来看看WinObjc项目到底如何使用. 开始之前 开始转制iOS项目前我们要先部署好WinObjc工具,工具链如下: 一台安装了Visual Studio的Windows 10 PC,2015社区版可以

关于目前自己iOS项目使用的第三方开源库

1.AFNetworking 目前比较推荐的iOS网络请求组件,默认网络请求是异步,通过block回调的方式对返回数据进行处理. 2.FMDB 对sqlite数据库操作进行了封装,demo也比较简单. 3.MBProgressHUD 也是iOS项目常用的一个组件,用于显示过渡效果的,比如网络请求之前显示loading,网络结束隐藏loading.建议封装在BaseViewController中,所有ViewController继承就能使用. 4.MJRefresh 这个是传智播客李明杰老师的作品

ios项目开发汇总

UI界面 iOS和Android 界面设计尺寸规范  http://www.alibuybuy.com/posts/85486.html iPhone app界面设计尺寸规范  http://www.wufangbo.com/ios-iphone-app/ iOS界面设计切图小结  http://www.apkbus.com/android-140341-1-1.html @2x图片等适应不同分辨率手机   http://blog.sina.com.cn/s/blog_945590aa0101c

ios项目开发(天气预报项目):使用正则获取 weather.com.cn网站信息

[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片 <pre code_snippet_id="346208" snippet_file_name="blog_20140515_1_2220869" name="code" class="cpp">- (NSString *)hmacsha1:(NSString *)text key:(NSString *)secret {

在Xcode 6 beta里编译Cocos2d-x iOS项目时失败

转载 在Xcode 6 beta里编译Cocos2d-x iOS项目时可能会失败,提示如下错误: Undefined symbols for architecture i386: "_fwrite$UNIX2003", referenced from: _unixErrorHandler in libcocos2dx iOS.a(tif_unix.o) _unixWarningHandler in libcocos2dx iOS.a(tif_unix.o) _empty_output_

为iOS项目添加Daily Build

很多人在说到Daily Build的时候总是喜欢背书.背书就背书吧,总比混迹软件行业连书都没看过的强.很久以前遇到一个奇葩.每次到代码提交测的通知就着急忙慌的催促组员赶紧干活,开始严重加班,晚饭都不吃...偶尔还需要开通宵.但是即使如此,最后也不会得到什么好的反馈.那个team就是这样循环往复的做着项目,直到永恒.如果项目的相关人员能背背敏捷什么的开发书籍,想必情况总能有所改善. 相信以上情况各位多少都遇到过,那么Daily Build为什么会对这样的情况有所改善呢? 快速定位错误.那天的Dai

Ios 项目从头开发 MVVM模式(一)

1.之前的项目一直用mvc开发ios,发现ios有一个弊端,mvc里,viewcontroller里边有大量的业务逻辑,当不断的修改,会发现只是一个痛苦的过程. 2.之前做wpf,使用过mvvm模式,可以把业务逻辑放到vm模式,vm可以来处理业务逻辑.做过几个ios项目,也想过mvvm模式,但是一直没找到.偶尔看到网上有一个mvvm模式的ios项目,我来尝试从头开始做这个项目,做完之后源码会公开. 3.ok,这个mvvm开源的项目是C-41,有兴趣的可以去网上搜搜. 4.这个项目要关联到一些类

IOS项目删除Git

默认创建工程会在MAC上面创建Git版本管理, 但是呢, 我现在想上传到svn服务器进行管理, 但是已经有个git 好像上传不了 只有把Git删了才能继续. 连问带查, 终于找到解决方案 把 .git 删掉 就是在你的ios项目文件目录下有一个.git的文件夹删掉, 开始接触ios的人一定不知道怎么弄, 因为.git文件夹是隐藏的 打开终端, 执行命令行defaults write com.apple.finder AppleShowAllFiles -bool true  显示隐藏文件 然后就

iOS项目架构文档

设计的项目架构主要引用MVVM+MVC架构,并以功能模块分级.以下为目录结构. 初级目录: 我们只需要关注SGZH文件夹下的目录,其他为Xcode管理的目录.可以看到此目录为项目初级目录,我们开发过程只需对初级目录内的文件进行操作,其主要划分为3大块: AppDelegate: AppDelegate是程序入口,程序启动和显示逻辑都定义在内部,主要可以让开发人员快速找到代理文件并了解程序从启动到显示过程,也可以快速进行一些初始化测试. Resource: 此目录主要存放一些项目资源文件,如项目切