定时刷新视图,写的一个小小的程序,一年前

//

//  ViewController.m

//  手机网易2

//

//  Created by BreazeMago on 15/1/7.

//  Copyright (c) 2015年 BreazeMago. All rights reserved.

//

#import "rootViewController.h"

@interface
rootViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,UIGestureRecognizerDelegate>

{

UIScrollView *scollView;

UIImageView  *adi1;

UIView
*navbar;

NSMutableArray  *adiImages1;

NSMutableArray  *adiSrc1;

NSMutableArray  *adiImages2;

NSMutableArray  *adiSrc2;

UIImageView  *bigImages;

NSInteger
adi1Index;

NSInteger
bigImagesIndex;

NSMutableArray  *newsButtons;

NSMutableArray  *detailTables;

}

@property (nonatomic,strong)
IBOutletUIView  *navbar;

@property (nonatomic,strong)
UIPageControl *pageControl;

@property (nonatomic,strong)
NSTimer *timer;

@property (nonatomic,strong)
UIScrollView  *scrollView1;

@property (nonatomic,strong)
UIScrollView  *scrollView2;

@property (nonatomic,strong)
IBOutletUIImageView  *adi1;

@property (nonatomic,strong)
IBOutletUIImageView  *bigImages;

@property (nonatomic,strong)
IBOutletNSMutableArray  *newsButtons;

@property (nonatomic,strong)
IBOutletNSMutableArray  *detailTables;

@end

@implementation rootViewController

@synthesize navbar;

@synthesize adi1;

@synthesize bigImages;

@synthesize newsButtons;

@synthesize detailTables;

@synthesize pageControl;

@synthesize timer;

@synthesize scrollView1;

@synthesize scrollView2;

// Implement loadView to create a view hierarchy programmatically, without using a nib.

-(void)addTimer

{

self.timer = [NSTimerscheduledTimerWithTimeInterval:5target:selfselector:@selector(nextImage)userInfo:nilrepeats:YES];

[[NSRunLoopcurrentRunLoop]
addTimer:self.timerforMode:NSRunLoopCommonModes];

}

-(void)nextImage

{

static
int page =0,page1 =
0;

if (page ==
2) {

page =0;

}else

{

page++;

}

if (page1 ==
1) {

page1 =0;

}else{

page1 =1;

}

CGFloat x = page *
self.scrollView1.frame.size.width;

self.scrollView1.contentOffset =CGPointMake(x,
0);

CGFloat x1 = page1 *
self.scrollView2.frame.size.width;

self.scrollView2.contentOffset =CGPointMake(x1,
0);

//NSLog(@"nextImage page1 = %d",page);

//NSLog(@"nextImage x = %f",x);

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGFloat scrollviewW =  scrollView.frame.size.width;

CGFloat x = scrollView.contentOffset.x;

int page = (x + scrollviewW /
2) /  scrollviewW;

self.pageControl.currentPage = page;

NSLog(@"nextImage page2 = %d",page);

}

- (void)removeTimer

{

[self.timerinvalidate];

}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

{

[selfremoveTimer];

}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

{

[selfaddTimer];

}

-(void)handleSwipFrom:(UISwipeGestureRecognizer*)gestureRecognizer

{

if(gestureRecognizer.direction ==UISwipeGestureRecognizerDirectionUp){

}elseif(gestureRecognizer.direction
==UISwipeGestureRecognizerDirectionDown){

}

}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

//3g.163.com/touch

adi1Index =
0;

bigImagesIndex =0;

scollView = [[UIScrollViewalloc]
initWithFrame:CGRectMake(0,20,320,1130)];

scollView.contentSize =CGSizeMake(0,1130);

scollView.pagingEnabled =YES;

UISwipeGestureRecognizer *swipRecognizer = [[UISwipeGestureRecognizeralloc]
initWithTarget:selfaction:@selector(handleSwipFrom:)];

[self.viewaddGestureRecognizer:swipRecognizer];//关键语句,给self.view添加一个手势监测;

swipRecognizer.delegate =self;

scollView.delegate =self;

////NSURL *Img4Url = [NSURL URLWithString:@"http://3g.163.com/touch/?from=index.toplogo"];

//UIImage *Img4 = [UIImage imageWithData:[NSData dataWithContentsOfURL:Img4Url]];

//UIImageView *navImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,0,80,40)];

//[navImageView setImage:Img4];

navbar = [[UIViewalloc]
initWithFrame:CGRectMake(0,0,320,40)];

navbar.backgroundColor =[UIColorredColor];

UIButton *btn1 = [[UIButtonalloc]
initWithFrame:CGRectMake(200,0,40,40)];

[btn1 setTitle:@"下载"forState:UIControlStateNormal];

[btn1 setTitleColor:[UIColorblackColor]
forState:UIControlStateNormal];

//[btn1 setBackgroundColor:[UIColor redColor]];

UIButton *btn2 = [[UIButtonalloc]
initWithFrame:CGRectMake(200+40,0,40,40)];

[btn2 setTitle:@"彩票"forState:UIControlStateNormal];

[btn2 setTitleColor:[UIColorblackColor]
forState:UIControlStateNormal];

//[btn2 setBackgroundColor:[UIColor yellowColor]];

UIButton *btn3 = [[UIButtonalloc]
initWithFrame:CGRectMake(200+80,0,40,40)];

[btn3 setTitle:@"导航"forState:UIControlStateNormal];

[btn3 setTitleColor:[UIColorblackColor]
forState:UIControlStateNormal];

//[btn3 setBackgroundColor:[UIColor blueColor]];

//[navbar addSubview:navImageView];

[scollView
addSubview:
navbar];

[scollViewaddSubview:btn1];

[scollViewaddSubview:btn2];

[scollViewaddSubview:btn3];

NSURL *Img1Url = [NSURLURLWithString:@"http://img1.126.net/channel6/2015/018439/640100_0105.jpg"];

UIImage *Img1 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img1Url]];

NSURL *Img2Url = [NSURLURLWithString:@"http://img1.126.net/channel6/640x100bbb.jpg"];

UIImage *Img2 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img2Url]];

NSURL *Img3Url = [NSURLURLWithString:@"http://img1.126.net/channel6/2015/018736/640100_0106.jpg"];

UIImage *Img3 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img3Url]];

adiImages1 = [[NSMutableArray alloc]
initWithObjects:Img1,Img2,Img3,nil];

adiSrc1 = [[NSMutableArray alloc]
initWithObjects:@"http://g.163.com/a?CID=32879&Values=584805076&Redirect=http://e.cn.miaozhen.com/r.gif?k=2002270&p=6rQFh&vo=369e37f12&vr=2&rt=2&ns=[M_ADIP]&ni=[M_IESID]&v=[M_LOC]&o=http://clk.gentags.net/nck/iv-9741/st-890/cr-2/oi-200925/or-3528/adv-122/pcon-0/mid=deviceid&t_ip=clientIp&os=OSType&rnd=rndm/http%253A%252F%252Fbetter.telunsu.net%252Fcny-m",@"http://caipiao.163.com/m/activity/dream.html?from=newspp3g",@"http://g.163.com/a?CID=32974&Values=112870580&Redirect=http://popme.163.com/link/018736_0107_2752.html",nil];

scrollView1  =[[UIScrollViewalloc]
initWithFrame:CGRectMake(0,40,
320,
40)];

CGFloat imageW =self.scrollView1.frame.size.width;

CGFloat imageH =self.scrollView1.frame.size.height;

CGFloat imageY =
0;

for(int i =0;i<3;i++){

UIImageView *imageView = [[UIImageViewalloc]
init];

CGFloat imageX = i * imageW;

imageView.frame =CGRectMake(imageX, imageY, imageW, imageH);

//imageView.image = [adiImages1 objectAtIndex:i];

scrollView1.showsHorizontalScrollIndicator =NO;

//scrollView1.showsVerticalScrollIndicator = NO;

[scrollView1addSubview:imageView];

}

CGFloat contentW =
3 *imageW;

scrollView1.contentSize =CGSizeMake(contentW,
0);

scrollView1.pagingEnabled =YES;

scrollView1.delegate =self;

[selfaddTimer];

[scollView
addSubview:scrollView1];

newsButtons = [[NSMutableArrayalloc]
initWithObjects:

@"新闻",@"独家",@"体育",@"娱乐",@"女人",@"财经",

@"汽车",@"手机",@"科技",@"游戏",@"军事",@"选股",

@"图片",@"房产",@"数码",@"博客",@"邮箱",@"小说",nil];/////

for(int i=0;i<[newsButtonscount];i++){

UIButton *btn4;

btn4= [[UIButtonalloc]
initWithFrame:CGRectMake(10+(i%6)*50,80+(i/6)*30,49,30)];

[btn4 setTitle:[newsButtonsobjectAtIndex: i]
forState:UIControlStateNormal];

[btn4 setTitleColor:[UIColorblackColor]
forState:UIControlStateNormal];

[scollViewaddSubview: btn4];

}

NSURL *Img5Url = [NSURLURLWithString:@"http://img5.cache.netease.com/3g/2015/1/7/201501072048056e7fe.jpg"];

UIImage *Img5 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img5Url]];

NSURL *Img6Url = [NSURLURLWithString:@"http://img1.126.net/channel6/2015/018517/640370_1229.jpg"];

UIImage *Img6 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img6Url]];

//adiSrc2 = [[NSMutableArray  alloc] initWithObjects:@"http://3g.163.com/touch/article.html?from=index&docid=AFCOUN1Owangyanfeng",@"http://g.163.com/a?CID=32621&Values=3219655259&Redirect=http://e.cn.miaozhen.com/r.gif?k=1017724&p=40fGn0&vo=313add540&vr=2&rt=2&ns=[M_ADIP]&ni=[M_IESID]&o=http%3A%2F%2Fevent.dianping.com%2Fmarket%2F201412mengniu%2Fapp%2Findex.html%3Fversion%3D*%26token%3D*",nil];

adiImages2 = [[NSMutableArrayalloc]
initWithObjects:Img5,Img6,nil];

//UIImageView *bigImagesView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 220, 320, 240)];

scrollView2  =[[UIScrollViewalloc]
initWithFrame:CGRectMake(0,170,
320,
240)];

CGFloat imageW1 =self.scrollView2.frame.size.width;

CGFloat imageH1 =self.scrollView2.frame.size.height;

CGFloat imageY1 =
0;

for(int i =0;i<2;i++){

UIImageView *imageView1 = [[UIImageViewalloc]
init];

CGFloat imageX1 = i * imageW1;

imageView1.frame =CGRectMake(imageX1, imageY1, imageW1, imageH1);

//imageView1.image = [adiImages2 objectAtIndex:i];

scrollView2.showsHorizontalScrollIndicator =NO;

//scrollView1.showsVerticalScrollIndicator = NO;

[scrollView2addSubview:imageView1];

}

CGFloat contentW1 =
2 *imageW1;

scrollView2.contentSize =CGSizeMake(contentW1,
0);

scrollView2.pagingEnabled =YES;

scrollView2.delegate =self;

[scollView
addSubview:scrollView2];

detailTables = [[NSMutableArrayalloc]
initWithCapacity:15];

UITableView *tabView1 = [[UITableViewalloc]
initWithFrame:CGRectMake(0,410,
320,
240)style:UITableViewStylePlain];

tabView1.delegate =self;

tabView1.dataSource =self;

[scollViewaddSubview:tabView1];

[detailTablesaddObject:tabView1];

/*

UIView *adiViewOne = [[UIView alloc] initWithFrame:CGRectMake(0, 700, 320, 40)];

UILabel *adiLabelOne = [[UILabel alloc] initWithFrame:CGRectMake(0, 700, 280, 40)];

adiLabelOne.text = @"3D动作冒险手游邀你来战";

NSString*adiSrcStr = @"http://txhd.163.com/newsapp/";

adiLabelOne.userInteractionEnabled = YES;

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickUILabel)];

[adiLabelOne addGestureRecognizer:tapGesture];

[adiViewOne addSubview :adiLabelOne];

[scollView addSubview:adiViewOne];

UITableView *tabView2 = [[UITableView alloc] initWithFrame:CGRectMake(0, 740, 320, 280) style:UITableViewStylePlain];

tabView2.delegate = self;

tabView2.dataSource = self;

UIView *headerView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 740, 320, 40)];

UILabel *headText1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 740, 80, 40)];

headText1.text = @"新闻";

headText1.numberOfLines = 0;

[headerView1 addSubview:headText1];

tabView2.tableHeaderView = headerView1;

[scollView addSubview:tabView2];

[detailTables addObject: tabView2];

UIView *adiViewTwo = [[UIView alloc] initWithFrame:CGRectMake(0, 1020, 320, 40)];

UILabel *adiLabelTwo = [[UILabel alloc] initWithFrame:CGRectMake(0, 1020, 280, 40)];

adiLabelTwo.text = @"免费送8+118元彩票!";

adiLabelTwo.userInteractionEnabled = YES;

[adiLabelTwo addGestureRecognizer:tapGesture];

[adiViewTwo addSubview : adiLabelTwo];

[scollView addSubview:adiViewTwo];*/

[self.viewaddSubview:scollView];

[superviewDidLoad];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return
1;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

int rows =
0;

if(tableView == [detailTablesobjectAtIndex :
0])

{

rows =4;

}else{

rows =8;

}

return rows;

}

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath
*)indexPath

{

return
5;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath

{

int height =
0;

if(tableView == [detailTablesobjectAtIndex :
0])

{

height =60;

}else{

height =30;

}

return height;

}

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

{

static
NSString *CellWithIdentifier =@"Cell";

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellWithIdentifier];

if (cell ==
nil) {

cell = [[UITableViewCellalloc]
initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellWithIdentifier];

}

NSURL *Img7Url = [NSURLURLWithString:@"http://img1.cache.netease.com/3g/2015/1/8/201501082026264a41b.jpg"];

UIImage *Img7 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img7Url]];

NSURL *Img8Url = [NSURLURLWithString:@"http://img2.cache.netease.com/3g/2015/1/8/20150108213013e203a.jpg"];

UIImage *Img8 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img8Url]];

NSURL *Img9Url = [NSURLURLWithString:@"http://img5.cache.netease.com/3g/2015/1/8/2015010814545338bd7.jpg"];

UIImage *Img9 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img9Url]];

NSURL *Img10Url = [NSURLURLWithString:@"http://img3.cache.netease.com/3g/2015/1/8/20150108110827d4c42.png"];

UIImage *Img10 = [UIImageimageWithData:[NSDatadataWithContentsOfURL:Img10Url]];

NSMutableArray *newsImgs1 = [[NSMutableArrayalloc]
initWithObjects:Img7,Img8,Img9,Img10,nil];

NSMutableArray *newsTitles1 = [[NSMutableArrayalloc]
initWithObjects:@"江绵恒卸任中科院上海分院长",@"海口一武警车鸣警笛强闯小学",@"林森浩:若死刑核准望捐献遗体",@"宣判后林父跌落椅子无法动弹",nil];

NSMutableArray *newsSubTitlesImgs1 = [[NSMutableArrayalloc]
initWithObjects:@"因年龄原因卸任,上海科技大学党委书记朱志远接任。",@"疑因车上一名女性家长的孩子发烧,事后该家长道歉。",@"付出年轻的生命来赔罪,希望这最后一件事能做对。",@"黄洋父母情绪失控痛哭不止,林森浩父亲称继续上诉。",nil];

NSUInteger row = [indexPath
row];

if(tableView == [detailTablesobjectAtIndex :
0])

{

cell.textLabel.text = [newsTitles1objectAtIndex:row];

//cell.imageView.image = [newsImgs1 objectAtIndex:row];

cell.detailTextLabel.text = [newsSubTitlesImgs1objectAtIndex:row];

}else{

cell.textLabel.text =@"大标题";

//cell.imageView.image = [UIImage imageNamed:@".png"];

cell.detailTextLabel.text =@"小标题";

}

return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath

{

/*

NSString *msg = [[NSString alloc] initWithFormat:@"??—°‘òμ? ?:%@",[self.dataList objectAtIndex:[indexPath row]]];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"?· ?" message:msg delegate:self cancelButtonTitle:@"?∑??" otherButtonTitles:nil, nil];

[msg release];

[alert show];

*/

}

@end

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-11 03:14:38

定时刷新视图,写的一个小小的程序,一年前的相关文章

swift __1 试写第一个swift程序

参照:http://swiftist.org/topics/96?page=2#comments 发现有几个地方一直报错,自己修改了下,有可能是xcode6更新导致 代码写的比较乱,这是我的硬伤,这次注释还是后面加上的,这也是我的硬伤,需要改.养成良好的代码习惯. 下面贴上自己的代码 // // ViewController.swift // SwiftCounter // // Created by 三十一 on 14-8-20. // Copyright (c) 2014年 yetuoxun

一个小小的程序Bug竟值400亿?

事件背景 日本公司J-Com在首次公开上市的日子就爆炸式地损失了超过400亿日元的天价损失,虽然日元那面额画得跟冥币似的,400亿日元也还是相当值些银子滴(按照当时的汇率,约为人民币27亿元). 事件的大致经过是由于一位操作员在离开盘还有几分钟的时候接到了一位客户"以61万日元的价格,卖出1股J-Com的股票"的委托,而田中君在接到委托后在交易终端上错误地输入了"以每股1日元的价格,卖出61万股". 至此,大家可想而知,事件继续发展下去会是怎样的灾难.但是,幸运的是

怎样写出一个递归程序

作为小白,我看到递归程序只是能看懂,但是自己写不出来,我知道要有一个临界条件(这个并不难找),但我不知道怎么演进,这让我十分头疼,因此找到了一篇个人认为写的不错的文章如下,根据我对递归的理解和疑问对原文做了一些标注,欢迎各位大佬,写下自己对递归的理解,本小白感激不尽. 如何写一个递归程序 总是听到大大们说递归递归的,自己写程序的时候却用不到递归.其中的原因,一个是害怕写递归,另一个就是不知道什么时候用递归.这篇文章就浅析一下,希望看完之后不再害怕递归,这就是本文最大的目的. 递归到底有什么意义?

Oracle查询库中已有存储过程、创建定时刷新视图、角色权限传递、创建序列触发器

SELECT * FROM V$ACCESS O WHERE O.TYPE LIKE 'PROCEDURE%' 创建物化视图且定时刷新create materialized view mv_name refresh force on demand start with sysdate next sysdate + 1create materialized view mv_name refresh force on demand start with sysdate next to_date( c

js 利用throw 写的一个小程序

在下边的小程序中比较特殊的是使用isNaN()函数判断一个参数是不是数字, 1 <!DOCTYPE html> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title></title> 6 7 <script type="text/javascript"> 8 function myFunction() { 9 10 var str = document.getElem

自己写的一个LINGO程序,欢迎指教

问题 9.一架货机有三个货舱:前舱.中仓和后舱.三个货舱所能装载的货物的最大重 量和体积有限制如表5 所示.并且为了飞机的平衡,三个货舱装载的货物重量必须与其 最大的容许量成比例. 表5 货舱数据 前舱 中仓 后舱 重量限制(吨) 10 16 8 体积限制(立方米) 6800 8700 5300 现有四类货物用该货机进行装运,货物的规格以及装运后获得的利润如表6. 表6 货物规格及利润表 重量(吨) 空间(立方米/吨) 利润(元/吨) 货物1 18 480 3100 货物2 15 650 380

用VS2019写第一个Python程序-Hello, Python!

第一步: 打开Visual Studio Installer,安装上Python开发环境. 第二步: 打开VS2019,新建Python项目,这里我选择了新建一个Python命令行应用程序. 解决方案命名为:HelloPython 生成的解决方案如图: 第三步: 使用Python的内置函数print (): 1 print ("Hello, Python!") 将上述代码粘贴到 HelloPython.py 文件,点击运行 结果如下图: 原文地址:https://www.cnblogs

Hadoop学习---第三篇Hadoop的第一个Mapreduce程序

Mapreducer程序写了好几个了,但是之前一直都没有仔细的测试过本地运行和集群上运行的区别,今天写了一个Mapreduce程序,在此记录下来. 本地运行注意事项有以下几点: 1.本地必须配置好Hadoop的开发环境 2.在src里不加入配置文件运行,或者如果本地的src里有mapred-site.xml和yarn-site.xml配置文件,那么mapreduce.framework.name=local以及yarn.resourcemanager.hostname=local 测试说明:sr

第一个CGI程序-----完全就是普通的c语言嘛‘(*∩_∩*)′

第一个CGI程序 ----完全就是普通的C语言嘛 '(*∩_∩*)′ PainterQ 2017年5月14日 上一篇博文里面叙述了Apache的安装和配置方法,恍恍惚惚我就拥有了自己的第一个http服务器.虽然是局域网下的网站但给同学们开开车还是完全够了(咳咳).好像是有了Apache再把HTTP文档丢到htdocs文件夹就可以了,老司机的工作竟然如此轻松.其实还有很多的姿势都还没有掌握哦,不追求新姿势的人生和咸鱼有什么分别!就是老司机也要做姿势最多的那一个.这一篇我们一起来了解一下什么是动态网