@interface ShaiXuanTypeViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UITableView * myTableView;
UIView * pinyinView;
NSArray * titleArr;
CGFloat ziMuHeight;
NSMutableDictionary * dataDic;
}
@end
@implementation ShaiXuanTypeViewController
- (void)viewDidLoad {
[super viewDidLoad];
titleArr=@[@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z"];
ziMuHeight=(MainScreenSize.height-NavBarHeight-10)/titleArr.count;
NSArray * arrA=@[@"Afghanistan", @"Albania", @"Algeria"];
NSArray * arrB=@[@"Bahrain"];
NSArray * arrC=@[ @"Comoros", @"Congo", @"Cook Islands", @"Czech Republic"];
NSArray * arrD=@[ @"Dominica",@"Dominican Republic"];
NSArray * arrE=@[@"East Timor", @"Ethiopia"];
NSArray * arrF=@[ @"French Guiana",@"French Polynesia"];
NSArray * arrG=@[@"Guinea-Bissau"];
NSArray * arrH=@[ @"Hong Kong",@"Hungary"];
NSArray * arrI=@[ @"Italy"];
NSArray * arrJ=@[@"Jamaica"];
NSArray * arrK=@[@"Kazakhstan"];
NSArray * arrL=@[@"Laos",@"Latvia",@"Lebanon"];
NSArray * arrM=@[@"Monaco",@"Marshall Islands"];
NSArray * arrN=@[@"Namibia", @"Norway"];
NSArray * arrO=@[@"Oman"];
NSArray * arrP=@[@"Pakistan"];
NSArray * arrQ=@[@"qatar"];
NSArray * arrR=@[@"Reunion", @"Romania", @"Russia", @"Rwanda"];
NSArray * arrS=@[@"Samoa"];
NSArray * arrT=@[@"Taiwan", @"Tanzania"];
NSArray * arrU=@[@"Uganda"];
NSArray * arrV=@[@"Vanuatu"];
NSArray * arrW=@[@"Wallis and Futuna", @"Western Sahara"];
NSArray * arrX=@[];
NSArray * arrY=@[@"Yemen", @"Yugoslavia"];
NSArray * arrZ=@[@"Zambia", @"Zimbabwe"];
NSArray * arr=@[arrA,arrB,arrC,arrD,arrE,arrF,arrG,arrH,arrI,arrJ,arrK,arrL,arrM,arrN,arrO,arrP,arrQ,arrR,arrS,arrT,arrU,arrV,arrW,arrX,arrY,arrZ];
dataDic=[NSMutableDictionary dictionary];
for (int i=0; i<titleArr.count; i++) {
[dataDic setObject:arr[i] forKey:titleArr[i]];
}
[self createTableView];
}
- (void)createTableView{
myTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, AutomaticWidth, AutomaticHeight-NavBarHeight)];
myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;//cell之间的线
myTableView.showsVerticalScrollIndicator=NO;
myTableView.delegate=self;
myTableView.dataSource=self;
myTableView.backgroundColor=[UIColor clearColor];
[self.view addSubview:myTableView];
pinyinView=[[UIView alloc]initWithFrame:CGRectMake(MainScreenSize.width-ziMuHeight, NavBarHeight, ziMuHeight, MainScreenSize.height-NavBarHeight)];
pinyinView.backgroundColor=[UIColor colorWithRed:0.19f green:0.19f blue:0.22f alpha:1.00f];
[self.view addSubview:pinyinView];
UIPanGestureRecognizer * panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureRecognizerClick:)];
[pinyinView addGestureRecognizer:panGesture];
for (int i=0; i<titleArr.count; i++) {
UIButton * zimuBt=[[UIButton alloc]initWithFrame:CGRectMake(0, pinyinView.frame.size.width*i, pinyinView.frame.size.width, pinyinView.frame.size.width)];
[zimuBt setTitle:titleArr[i] forState:UIControlStateNormal];
[zimuBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
zimuBt.titleLabel.font=[UIFont systemFontOfSize:14];
[pinyinView addSubview:zimuBt];
zimuBt.tag=i;
[zimuBt addTarget:self action:@selector(selClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
- (void)panGestureRecognizerClick:(UIPanGestureRecognizer *)panGesture{
//拖动到指定字母
if (panGesture.state == UIGestureRecognizerStateEnded) {
CGPoint endPoint = [panGesture locationInView:pinyinView];
NSInteger index = endPoint.y/ziMuHeight;
// NSLog(@"======%@",titleArr[index]);
[myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return dataDic.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray * arr = [dataDic objectForKey:titleArr[section]];
return arr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 25;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UILabel * titLab=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, MainScreenSize.width, 25)];
titLab.text=titleArr[section];
titLab.textAlignment=NSTextAlignmentCenter;
titLab.backgroundColor=[UIColor colorWithRed:0.19f green:0.19f blue:0.22f alpha:1.00f];
titLab.textColor=[UIColor whiteColor];
return titLab;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * identy=@"mycell";
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:identy];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identy];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor clearColor];
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.textLabel.textColor=[UIColor whiteColor];
cell.textLabel.font=[UIFont systemFontOfSize:14];
NSArray * arr = [dataDic objectForKey:titleArr[indexPath.section]];
cell.textLabel.text=arr[indexPath.row];
UIImageView * lineView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, MainScreenSize.width-ziMuHeight-5, 0.5)];
// lineView.backgroundColor=[UIColor colorWithRed:0.19f green:0.19f blue:0.22f alpha:1.00f];
lineView.image=[UIImage imageNamed:@"Y筛选_03.png"];
[cell.contentView addSubview:lineView];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell=[tableView cellForRowAtIndexPath:indexPath];
NSString * selStr=cell.textLabel.text;
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
[user setObject:selStr forKey:SelStrInType];
[user synchronize];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)selClick:(UIButton *)button{
//点击到指定字母
[myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:button.tag] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
类似通讯录的列表
最新推荐文章于 2018-03-02 09:34:29 发布