下面记录的是自己学习UITableView表格视图 和android的ListView类似
viewDidLoad
_tableview=[[UITableView alloc]intiWithFrame:view.bounds style:UITableViewStylePlain];
_listarr=@[@"list1",@"list2"];//数据
_tableview.datasource=self; //数据委托
_tableview.delegate=self; //uitable委托
[self.view addSubview:_tableview];
下面是两个必须去实现的委托
numberOfRowsInSection //每个section的个数
retrun [_listarr count];
cellForRowAtIndexPath //实现数据添加
stratic NSString *cellid=@"cell";
UITableViewCell *cell=[tableView dequeneReuasbleCellWithIdentfirer:cellid];
if(cell==nil)
{
cell=[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
}
NSString *name=_listarr[indexPath,row];
cell.textLabel.text=name;
return cell;
下面是选择实现的委托
//section的标题名称
titleForheaderInsection
return name;
//section的高度
heightForHeaderIsetcion
//选择的是某行
didSelectRowAtIndexPath
//下面是从plist加载字典
加载字典包
NSString *listpath=[NSBundle mainBundle]pathForResource:@"listData" ofType:@"plist"];
//加入字典
NSDictionary datadic=[NSDictionary dictionaryWIthContentsOfFile:listpath];
//字典转成数组
NSArray *mylist=[NSArray arrarWithArray:[datadic allKeys]];
//数组排序
_plist=[mylist sortedArrayUsingSelector:@selector(compare:)];
cell的几个定制方法
1:cell=[x alloc]init style];
[cell.contentView addSubview:myview];
UILabel *label=(UILabel*)[cell.contentView viewWithTag:101];
label.text=_listArray[indexPath.row];
2: NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"View" ower:self options:nil];
cell=[nibs objectAtIndex:0];
UILabel *label=(UILabel*)[cell.contentView viewWithTag:101];
label.text=_listArray[indexPath.row];
3:子类化
覆盖layoutSubviews
下面是 UIScrollView
UIScrollView *csroll=[UiScrollView alloc]initWithFrame:CGRectMake(0,0,320,400)];
csroll.contentSize=CGSizeMake(320*2,400);
csroll.pagingEnabled=YES;
csroll.indicatorStyle=UIScrollViewIndicatorStyleWhite;
[csroll flashScrollIndicators];
csroll.contentInset=UIEdgeInsetsMake(0,20,0,0);
csroll.directionalLockEnabled=YES;//是否同时运动
//事件
[scrollView setContentOffset:CGPointMake(320,0) animated:YES];
// 代理拖拽减速结束
(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if([scrollView isMemberOfClass:[UITableView class]])
{
//uitableview
}
else
{
int con=scrollView.contentOffset.x/320;
UIpageControl *page=(UIpageControl)[self.view viewWithTag:110];
page.currentPage=con;
}
}
//图片的 viewdidload
scrollView.minimumZoomScale=0.5 //最小的
scrollView.maximumZoomScale=2 //最大的
self.scrollView.delegate=self;
_imageView=[[UiImageView alloc]initWithFrame:CGRectMake(0,0,320,460)];
_imageView.image=[UIImage imageNamed:@"1.jpg"];
[scrollView addSubview:_imageView];
//对图片的缩小的放大
-(UIView*)viewForZoomingInScrollview:(UIScrollView *)scrollView
{
return _imageView;
}
/ photo
scroview.tag=i;
int pre=0;
(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int con=scrollView.contentOffset.x/320;
ImageScrollView *imaScrollView=(ImageScrollView *)[scrollView viewWithTag:pre];
if(current!=pre&&imgScrollView.zommScale>1)
imgScrollView.zoomScale=1;
pre=con;
}
}
//处理双击事件
-(void)zoomInorOut:(UITapGestureRecognizer *)tapGesture
{
if(self.zoomScale>=2.5)
[self setZommScale:1 animated:YES];
else
{
CGpoint point [tapGesture locationInView:self];
[self zoomToRect:CGRectMake(point.x-40,point.x-40,80,80) animated:YES];
}
}
在 myimagescorllview
UITapGestureRecognizer *double=[UITapGestureRecongnizer alloc]initWithTarget:self action:@selector(zoomINorOUt:)];
doubleTap.numberofTapsRequired=2;
[self addGestureRecognizer:douleTap];