TableViewCell的点击打钩
来源:互联网 发布:零基础学qt4编程 编辑:程序博客网 时间:2024/04/29 23:59
//
// ViewController.m
// TableViewCell的点击打钩
//
// Created by siqiyang on 16/4/15.
// Copyright © 2016年 mengxianjin. All rights reserved.
//
#import "ViewController.h"
#import "ChineseToPinyin.h"
#define SCREEN_WIDTH ([[UIScreen mainScreen]bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen]bounds].size.height)
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSInteger currentIndex;
NSInteger currentsection;
}
@property (nonatomic,strong)NSMutableArray *classArray;
@property (nonatomic,strong)UITableView *classTableview;
@property (nonatomic,strong)NSMutableArray *indexArr;
@property (nonatomic,strong)NSMutableDictionary *dataDic;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
_classArray = [[NSMutableArrayalloc]init];
_indexArr = [[NSMutableArrayalloc]init];
_dataDic = [[NSMutableDictionaryalloc]init];
currentIndex = -1;
currentsection = -1;
_classTableview = [[UITableViewalloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,SCREEN_HEIGHT)style:UITableViewStylePlain];
_classTableview.delegate =self;
_classTableview.dataSource =self;
_classTableview.tableFooterView = [[UIViewalloc]init];
if ([_classTableviewrespondsToSelector:@selector(setSeparatorInset:)]) {
[_classTableviewsetSeparatorInset:UIEdgeInsetsMake(0,0, 0,0)];
}
if ([_classTableviewrespondsToSelector:@selector(setLayoutMargins:)]) {
[_classTableviewsetLayoutMargins:UIEdgeInsetsMake(0,0, 0,0)];
}
[self.viewaddSubview:_classTableview];
[selfgetClassData];
}
//- (void)addSelectedSchoolLabel{
// UILabel *selectedLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
// selectedLabel.backgroundColor = [UIColor colorWithHexString:@"#363636"];
// selectedLabel.textColor = [UIColor whiteColor];
// selectedLabel.text = [NSString stringWithFormat:@"%@:%@",@"已选择学校",self.schoolName];
// [self.view addSubview:selectedLabel];
//}
/**
* 获取班级信息
*/
- (void)getClassData{
if (_classArray.count !=0) {
[_classArrayremoveAllObjects];
if (_classArray ==nil) {
_classArray = [NSMutableArrayarray];
}
}
//
NSArray *classes =@[@"三班",@"五班",@"无敌班",@"春天班",@"秋香班",@"唐寅班",@"夏荷班",@"冬梅班",@"香山班",@"北京班",@"上海班",@"广州班",@"杭州班",@"福州班",@"兰州班",@"深圳班",@"西安班",@"青岛班",@"哈尔滨班",@"沈阳班",@"大连班",@"南京班",@"济南班",@"郑州班",@"石家庄班",@"唐山班",@"张家口班",@"呼和浩特班",@"包头市班",@"长春市班",@"宁波市班",@"三明市班",@"济宁市班",@"日照班",@"vvgf",@"wrwr",@"#$rwfs",@"@#324$%#",@"2@23#$!"];
for (NSString *classNamein classes) {
[_classArray addObject:className];
}
_indexArr = [selfgetIndexArr:_classArray];
for (NSString *indexStrin _indexArr) {
NSMutableArray *sourceArray = [[NSMutableArrayalloc]init];
for (NSString *classStrin _classArray) {
char firstChar = pinyinFirstLetter([classStr characterAtIndex:0]);
NSString *className = [[NSStringstringWithFormat:@"%c",firstChar]uppercaseString];
if ([indexStr isEqualToString:className]) {
[sourceArray addObject:classStr];
}
}
[_dataDic setObject:sourceArray forKey:indexStr];
}
[_classTableviewreloadData];
}
#pragma mark -- 获取数组中的首字母合集
//获取数组中的首字母合集
- (NSMutableArray *)getIndexArr:(NSArray *)arr{
NSMutableArray *indexArray = [NSMutableArrayarray];
//获取字母列表
for (int i =0; i <arr.count; i++) {
char firstChar = pinyinFirstLetter([[arr objectAtIndex:i]characterAtIndex:0]);
NSString *schoolName = [NSStringstringWithFormat:@"%c",firstChar];
//不添加重复元素
if (![indexArray containsObject:[schoolName uppercaseString]]) {
[indexArray addObject:[schoolName uppercaseString]];
}
}
[indexArray sortUsingSelector:@selector(compare:)];
return indexArray;
}
#pragma mark -- tableViewdatasource
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
if (tableView == _classTableview) {
return _indexArr;
}
return nil;
}
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section {
NSInteger tempSection = section;
NSString *key = [_indexArrobjectAtIndex:tempSection];
return key;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return_indexArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView
sectionForSectionIndexTitle:(NSString *)title
atIndex:(NSInteger)index {
NSInteger count = 0;
for(NSString *characterin _indexArr)
{
if([character isEqualToString:title]) return count;
count ++;
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *tempArr = [NSArrayarray];
if (_dataDic &&_indexArr) {
tempArr = [_dataDic objectForKey:[_indexArr objectAtIndex:section]];
}
if (tempArr.count !=0) {
return tempArr.count;
}
else
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId =@"class";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
}
//获取section上的串
NSString *sectionStr = [NSStringstringWithFormat:@"%@",_indexArr[indexPath.section]];
NSArray *classArr = [_dataDicobjectForKey:sectionStr];
cell.textLabel.text =classArr[indexPath.row];
if (currentsection == indexPath.section) {
if (indexPath.row ==currentIndex) {
UIImageView *accessoryView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 19, 16)];
accessoryView.image = [UIImageimageNamed:@"icon_check_sel"];
cell.accessoryView = accessoryView;
}
else
cell.accessoryView = nil;
}
else
cell.accessoryView = nil;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
currentIndex = indexPath.row;
currentsection = indexPath.section;
[_classTableviewreloadData];
}
- (void)submitApplication:(id)sender{
UIView *backView = (UIView *)[self.viewviewWithTag:555];
if (backView != nil) {
[backView removeFromSuperview];
}
UIView *alertView = (UIView *)[self.viewviewWithTag:600];
if (alertView != nil) {
[alertView removeFromSuperview];
}
[self.navigationControllerpopToViewController:[self.navigationController.viewControllersobjectAtIndex:2] animated:YES];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- TableViewCell的点击打钩
- TableViewCell 里面嵌的TableViewCell 如何点击里面的TableViewCell进行页面跳转?
- 获取tableViewCell点击的位置和indexPath
- 点击tableViewCell,调用打电话的功能
- TableViewCell 自定义点击的高亮颜色
- 打钩的动画
- C# 中TreeView 控件实现点击CheckBoX自动打钩的事件
- tableViewCell点击效果
- 隐藏tableViewCell点击效果
- iOS tableviewCell点击行高变高
- 嵌套的tableviewcell 内的控件的点击协议实现
- 简洁代码之点击tableViewCell加载不同的视图
- iOS 手势 点击tableViewCell 传不同的值
- 点击tableViewCell中的一个按钮,打印cell所在的行
- iOS自定义tableViewCell中的按钮无法点击的解决方法
- 自定义tableviewcell 被点击之后显示的内容消失
- TableViewCell 点击跳转多个不同的界面
- 微软Excel 2007 框里打钩/打钩的方框选择
- HDU-1010-Tempter of the Bone(搜索奇偶剪枝)
- 一些常用算法的代码(1)
- nyoj166-小珂的数学题
- sass不支持GBK
- iOS APP上架流程
- TableViewCell的点击打钩
- 【linux】linux下安装Node.js
- POJ-3100-Root of the Problem,原来是水题,暴力求解~~~
- memcached出现:Fatal error: Call to undefined method Memcached::connect()
- poj 1860 Currency Exchange bellman
- ArcGIS Runtime SDK for iOS(四) ---使用geometry的原始数据重绘折线
- iOS小技巧 - 利用GCD创建更加准确的定时器
- summary:http乱码
- hdu HDU Today2112