博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS-UI篇—简单的浏览器查看程序和Tomcat简单实现
阅读量:6943 次
发布时间:2019-06-27

本文共 3073 字,大约阅读时间需要 10 分钟。

1 #import "ViewController.h" 2  3 @interface ViewController () 4  5 @property (retain, nonatomic) NSArray *pic; 6 @property (assign, nonatomic) NSInteger index; 7 @property (weak, nonatomic) IBOutlet UILabel *lblIndex; 8 @property (weak, nonatomic) IBOutlet UILabel *lblTitle; 9 @property (weak, nonatomic) IBOutlet UIImageView *picture;10 - (IBAction)nextPicture:(id)sender;11 @property (weak, nonatomic) IBOutlet UIButton *btnnext;12 13 - (IBAction)lastPicture:(id)sender;14 @property (weak, nonatomic) IBOutlet UIButton *btnLast;15 16 @end17 @implementation ViewController18 19 20 - (void)viewDidLoad {21     [super viewDidLoad];22     //让第一个图片显示出来,所以先调用一次23     [self nextPicture:nil];24 }25 26 - (void)didReceiveMemoryWarning {27     [super didReceiveMemoryWarning];28 }29 30 // 重写pic属性get方法---懒加载数据31 - (NSArray *)pic32 {   /*33      写代码加载picture.plist文件中的数据到_pic;34      1.获取picture.plist文件的路径35      ps:[NSBundle mainBundle]获取这个app安装到手机上时的根目录36      然后在根目录下搜索picture.plist文件路径37      */38     if (_pic == nil) {39         NSString *string = [[NSBundle mainBundle] pathForResource:@"picture" ofType:@".plist"];40         NSArray *array = [NSArray arrayWithContentsOfFile:string];41         //NSLog(@"%@",array);42         43         _pic = array;44         45     }46     return _pic;47 }48 49 - (IBAction)nextPicture:(id)sender {50     //1.让索引自加51     _index++;52     //2.从数组中获取当前这张图片的数据53     NSDictionary *dict = self.pic[self.index-1];54     //3.把获取到得数据设置给界面上的控件55     self.lblIndex.text = [NSString stringWithFormat:@"%ld/%ld",self.index,self.pic.count];56     //4.通过image属性来设置图片框里面的图片57     self.picture.image =[UIImage imageNamed: dict[@"picture"]];58     59     self.lblTitle.text = dict[@"title"];60     //设置“下一张”按钮是否可以点击61     self.btnnext.enabled =( _index != self.pic.count);62     //设置“上一张”按钮是否可以点击63     self.btnLast.enabled =( _index-1 != 0);64 65 }66 67 - (IBAction)lastPicture:(id)sender {68     _index--;69     NSDictionary *dict = self.pic[self.index-1];70     self.lblIndex.text = [NSString stringWithFormat:@"%ld/%ld",self.index,self.pic.count];71     self.picture.image =[UIImage imageNamed: dict[@"picture"]];72     self.lblTitle.text = dict[@"title"];73     74     self.btnLast.enabled =( _index-1 != 0);75     self.btnnext.enabled =( _index != self.pic.count);76 }77 @end

 

开发思路:

1.完成基本功能

2.考虑性能

(1)(初始化操作,可以直接调用change进行)

(2)因为要控制序号和图片两个变量,所以考虑使用字典代替掉switch

(3)每次点击,字典都需要创建一次,效率地下,可以考虑创建的这部分拿到初始化方法中去,这样就只需要创建一次就ok了。

(4)考虑缺点(对代码的顺序要求极其严格)

(5)懒加载(需要的时候才加载,那么什么时候是需要的时候,及调用get方法的时候)

(6)每次都来一下?效率低下—》只有第一次调用get方法时为空,此时实例化并建立数组,其他时候直接返回成员变量(仅仅执行一次)

注意点:

1.方法的调用堆栈(顺序)。

2.使用plist:让数据的操作更加灵活,把数据弄到外面去,解除耦合性,让耦合性不要太强。实际上是一个xml,是苹果定义的一种特殊格式的xml。

3.bundle-包(只读)

 

二、Tomcat简单实现(吃小鸟)

1 - (IBAction)eatBird:(id)sender { 2      3     [self startAnimating:40 picName:@"cat_eat"]; 4 } 5  6 - (void)startAnimating:(int)count picName:(NSString *)picName 7 { 8     // 如果当前图片框正在执行动画,那么直接return,什么也不做 9     if (self.imageViewCat.isAnimating) {10         return;11     }12     // 1.加载图片到数组中13     NSMutableArray *array = [NSMutableArray array];14     for (int i=0; i

 

转载地址:http://hfinl.baihongyu.com/

你可能感兴趣的文章
浅谈Java字符串(操作)
查看>>
精读《React 的多态性》
查看>>
JQuery实现注册表单验证
查看>>
solr7安装(1)
查看>>
我为NET狂~群福利:逆天书库
查看>>
UNIX文件I/O
查看>>
说说React组件的State
查看>>
央视会玩,2017年春晚或推出VR直播
查看>>
c#扩展方法的使用
查看>>
Xamarin android 调用Web Api(ListView使用远程数据)
查看>>
always on 集群
查看>>
CentOS下LAMP一键yum安装脚本
查看>>
[20180403]关于时区问题.txt
查看>>
满足各种需求,德阳人民医院Wi-Fi覆盖选择飞鱼星
查看>>
疯狂剁手之后 平台帮了谁又肥了谁?
查看>>
8 个必备的PHP功能开发
查看>>
纳德拉:云计算是重要增长点18年目标200亿
查看>>
聚焦“微服务与容器云” 2017CIO时代线下CIO沙龙顺利举行
查看>>
入行数据科学,仅需6步
查看>>
Linux虚拟化技术KVM、QEMU与libvirt的关系(转)
查看>>