ios中的轮播图跟gridview的复用
来源:互联网 发布:yum命令搜索 编辑:程序博客网 时间:2024/04/29 08:16
轮播图现在是比较常用的,所以下面就贴一些代码,供新手跟懒人(请不要对号入座)使用
轮播图跟gridview复用更是多
-(void)requestFinished:(ASIHTTPRequest *)request
{
[JYHAPIcloseLoading:self.view];
if (request.tag ==100) {
home_indexdataExist =2;
NSString *responseStr = [request responseString];
NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* dic = [NSJSONSerializationJSONObjectWithData:jsonData options:NSJSONReadingAllowFragmentserror:nil];
NSDictionary *list = [dic objectForKey:@"list"];
//NSArray *array = [dic objectForKey:@"list"];
// NSLog(@"xuhaoarray = %@",array);
for(NSDictionary*dic1in list)
{
HomePageItem *item = [[HomePageItemalloc] init];
item.adId = [dic1 objectForKey:@"adId"];
item.title = [dic1 objectForKey:@"title"];
item.image = [dic1 objectForKey:@"image"];
item.couponId = [dic1 objectForKey:@"couponId"];
item.type = [dic1 objectForKey:@"type"];
item.url = [dic1 objectForKey:@"url"];
item.open = [dic1 objectForKey:@"open"];
item.cataId = [dic1 objectForKey:@"cataId"];
[headImageArray addObject:item.image];
[headTitleArray addObject:item.title];
[headViewIDArray addObject:item.adId];
[dataArray addObject:item];
}
headerView = [[UIViewalloc] init];
if ([[[UIDevicecurrentDevice] systemVersion] floatValue] >= 7)
{
headerView.frame =CGRectMake(0,64,kScreenWidth, 160);
}else
headerView.frame =CGRectMake(0, 44,kScreenWidth, 160);
headerView.userInteractionEnabled =YES;
sv = [[UIScrollViewalloc] initWithFrame:CGRectMake(0,0, kScreenWidth,150)];
sv.contentSize =CGSizeMake(kScreenWidth * [dataArraycount], 150);
sv.backgroundColor = [UIColorredColor];
sv.delegate =self;
sv.pagingEnabled =YES;
sv.showsHorizontalScrollIndicator =NO;
sv.showsVerticalScrollIndicator =NO;
sv.userInteractionEnabled =YES;
[headerView addSubview:sv];
pc = [[UIPageControlalloc] initWithFrame:CGRectMake(0,140, kScreenWidth,10)];
pc.numberOfPages = [dataArraycount];
[headerView addSubview:pc];
for (int i =0; i < [dataArray count]; i++)
{
UIButton *imageBtn = [[UIButtonalloc]initWithFrame:CGRectMake(i*320,0, 320, 160)];
UIImageView *imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(i*320,0, 320, 160)];
UILabel *adTitleLable = [[UILabelalloc] initWithFrame:CGRectMake(i*320+5,110, 310, 25)];
adTitleLable.text = [NSStringstringWithFormat:@"%@",[headTitleArrayobjectAtIndex:i]];
adTitleLable.backgroundColor = [UIColorgrayColor];
adTitleLable.font = [UIFontsystemFontOfSize:14];
adTitleLable.textAlignment = UITextAlignmentCenter;
[imageView setImageWithURL:[NSURLURLWithString:[headImageArray objectAtIndex:i]]placeholderImage:[UIImageimageNamed:@"qq.png"]];
imageView.userInteractionEnabled =YES;
[imageBtn setBackgroundImage:[UIImageimageNamed:@"qq.png"]forState:UIControlStateNormal];
[imageBtn addTarget:selfaction:@selector(btn:)forControlEvents:UIControlEventTouchUpInside];
imageBtn.alpha = 0.05;
imageBtn.tag = [[headViewIDArrayobjectAtIndex:i]integerValue];
[sv addSubview:imageView];
[sv addSubview:imageBtn];
[sv addSubview:adTitleLable];
}
// gridView = [[UIGridView alloc] initWithFrame:CGRectMake(0, 44, kScreenWidth, kScreenHeight- 120)];
gridView = [[UIGridViewalloc] init];
if ([[[UIDevicecurrentDevice] systemVersion] floatValue] >= 7)
{
gridView.frame =CGRectMake(0, 64,kScreenWidth, kScreenHeight- 110);
}else
gridView.frame =CGRectMake(0, 44,kScreenWidth, kScreenHeight- 120);
gridView.backgroundColor = [UIColorclearColor];
gridView.uiGridViewDelegate =self;
gridView.showsHorizontalScrollIndicator =NO;
gridView.showsVerticalScrollIndicator =NO;
[gridViewsetTableHeaderView:headerView];
[self.view addSubview:gridView];
NSTimer *timer = [NSTimerscheduledTimerWithTimeInterval:3.0target:selfselector:@selector(tick)userInfo:nilrepeats:YES];
[timer fire];
}else{
home_addataExist =2;
NSString *responseStr = [request responseString];
NSData *jsonData = [responseStrdataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* dic = [NSJSONSerializationJSONObjectWithData:jsonData options:NSJSONReadingAllowFragmentserror:nil];
NSDictionary *list = [dic objectForKey:@"list"];
for(NSDictionary*dic1in list)
{
HomePageItem *item = [[HomePageItemalloc] init];
item.cataId = [dic1 objectForKey:@"cataId"];
item.cataName = [dic1 objectForKey:@"cataName"];
item.cataLogo = [dic1 objectForKey:@"cataLogo"];
item.cataIndex = [dic1 objectForKey:@"cataIndex"];
item.P_cataId = [dic1 objectForKey:@"P_cataId"];
[dataArray1 addObject:item];
}
[gridViewreloadData];
}
}
-(void)btn:(UIButton *)sender
{
// NSLog(@"fsfs=%d",sender.tag);
for (int i =0; i<headViewIDArray.count; i++) {
HomePageItem *item = [dataArrayobjectAtIndex:i];
if (sender.tag == item.adId.integerValue)
{
NSLog(@"xuhaotap撒旦法撒旦法撒旦法==%@",item.type);
if (item.type.integerValue ==0) {
return;
}else if(item.type.integerValue ==1)
{
if (item.open.integerValue ==0) {
[[UIApplication sharedApplication]openURL:[NSURLURLWithString:item.url]];
}else
{
NSLog(@"web");
WebViewViewController *web = [[WebViewViewControlleralloc] init];
web.url = item.url;
[self.navigationControllerpushViewController:web animated:NO];
}
}else if (item.type.integerValue ==2)
{
AllInfoViewController *allInfo = [[AllInfoViewControlleralloc] init];
allInfo.ID = item.couponId;
[self.navigationControllerpushViewController:allInfo animated:NO];
}else
{
// AllViewController *all = [[AllViewController alloc] init];
// all.cataId = item.cataId;
// [self.navigationController pushViewController:all animated:NO];
AllViewController *all = [[AllViewControlleralloc] init];
all.cataId = item.cataId;
NSLog(@"all.cataId=%@",all.cataId);
[self.navigationControllerpushViewController:all animated:NO];
}
}
}
}
-(void)backBtnClick
{
AllViewController *all = [[AllViewControlleralloc]init];
[self.navigationControllerpushViewController:all animated:NO];
}
//自动播放图片的函数
- (void)tick
{
if ([headImageArraycount] >= 2)
{
if (tickIndex >= [headImageArraycount])
{
tickIndex = 0;
}
CGFloat pageWidth = sv.frame.size.width;
[svsetContentOffset:CGPointMake(tickIndex * pageWidth,0) animated:YES];
pc.currentPage =tickIndex;
courseTitleLable.text = [corseTitleArrayobjectAtIndex:tickIndex];
tickIndex ++;
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"dsdfsaend");
pc.currentPage = scrollView.contentOffset.x/320;
tickIndex = pc.currentPage;
courseTitleLable.text = [corseTitleArrayobjectAtIndex:pc.currentPage];
}
此代码是在ARC的环境下编写的,其中有许多不足之处,跪求指正,当然了,不是很明白的也可以问我- ios中的轮播图跟gridview的复用
- JS操作GridView,JS获取table的td中的值跟控件
- gridview跟ObjectDatasource的一些说明与
- 关于ListView,GridView的Adapter中的复用问题
- Gridview事件跟它item布局中的控件事件冲突
- mybatis中的#{}跟${}的区别
- 解决ScrollView跟ListView或GridView嵌套时的问题
- Android中的GridView的运用
- iOS instancetype 跟 id 的区别
- iOS NSRunLoop跟NSTimer的问题
- iOS 成员变量跟属性的区别
- iOS Documents、Library跟tmp的作用
- ios bool跟BOOL的区别
- iOS静态库的创建跟使用
- asp.net 2.0中的gridview里用crosspage的功能
- 关于用ImageButton删除GridView中的记录不成功的问题
- 非常好用的GridView控件yyControls中的SmartGridView
- asp.net 2.0中的gridview里用crosspage的功能
- 对mahout与hadoop的调用关系分析,以及建立统一化平台的思路
- linux下目录操作
- vmware中红帽linux的上网
- sql server触发器及存储过程
- 进程外COM组件的一个实例
- ios中的轮播图跟gridview的复用
- 代码测试之代码调试
- IOS系列——delegate和protocol
- oracle序列及触发器
- 一些下载交叉编译环境的地址
- [已解决]IE按F12任务栏会出现“开发人员工具”按钮,但窗口不显示
- 初识php
- 【IOS网络编程】socket编程 - Asyncsocket
- 写程序的注意点