Iphone之UITableView
来源:互联网 发布:计算机视觉python 编辑:程序博客网 时间:2024/06/05 00:14
UITableView应该是在开发中运用最多的控件之一。所以必须很熟悉。
UITableView的定义和初始化:
- UITableView *table = [[UITableView alloc] initWithFrame:HC_SystemTableViewFrame
- style:UITableViewStyleGrouped];
和一般控件似乎没有什么却别。
初始化控件后就是将UITableView画成自己想要的效果
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *Cell = @"CELL";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil)
- {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:Cell] autorelease];
- }
- NSArray *array = [NSArray arrayWithObjects:@"振动", @"声音", @"消息提醒设置",@"主题", nil];
- NSArray *arrayList = [dataList objectForKey:[array objectAtIndex:indexPath.section]];
- cell.tag = indexPath.section;
- switch (indexPath.section) {
- case 0:
- {
- cell.textLabel.text = [arrayList objectAtIndex:indexPath.row];
- cell.textLabel.textAlignment = UITextAlignmentLeft;
- cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
- UISwitch *swit = [[UISwitch alloc] initWithFrame:CGRectMake(180, 8, 70, 40)];
- NSInteger switStatus = [[[MessageCenter shareInstance].settingDic objectForKey:@"setVibrate"] integerValue];
- swit.on = switStatus;
- [swit addTarget:self action:@selector(addVibrate:) forControlEvents:UIControlEventValueChanged];
- [cell.contentView addSubview:swit];
- [swit release];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- break;
- }
- case 1:
- {
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.textLabel.text = [arrayList objectAtIndex:indexPath.row];
- cell.textLabel.textAlignment = UITextAlignmentLeft;
- cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
- UISwitch *swit = [[UISwitch alloc] initWithFrame:CGRectMake(180, 8, 70, 40)];
- NSInteger switStatus1 = [[[MessageCenter shareInstance].settingDic objectForKey:@"setSound"] integerValue];
- swit.on = switStatus1;
- [swit addTarget:self action:@selector(addSound:) forControlEvents:UIControlEventValueChanged];
- [cell.contentView addSubview:swit];
- [swit release];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- break;
- }
- case 2:
- {
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.textLabel.text = [arrayList objectAtIndex:indexPath.row];
- cell.textLabel.textAlignment = UITextAlignmentLeft;
- cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
- UISwitch *swit = [[UISwitch alloc] initWithFrame:CGRectMake(180, 8, 70, 40)];
- NSInteger switStatus2 = [[[MessageCenter shareInstance].settingDic objectForKey:@"setNotification"] integerValue];
- swit.on = switStatus2;
- [swit addTarget:self action:@selector(addNotification:) forControlEvents:UIControlEventValueChanged];
- [cell.contentView addSubview:swit];
- [swit release];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- break;
- }
- case 3:
- {
- cell.textLabel.text = [arrayList objectAtIndex:indexPath.row];
- cell.textLabel.textAlignment = UITextAlignmentCenter;
- cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- MessageCenter *mgCenter = [MessageCenter shareInstance];
- UILabel *lable = (UILabel *)[cell.contentView viewWithTag:101];
- if (lable != 0)
- [lable removeFromSuperview];
- lable = [[UILabel alloc] initWithFrame:CGRectMake(200, 14, 70, 20)];
- lable.backgroundColor = [UIColor clearColor];
- lable.text = @"";
- lable.tag = 101;
- lable.textAlignment = UITextAlignmentRight;
- lable.font = [UIFont systemFontOfSize:13];
- if (mgCenter.themeSetName != nil)
- lable.text = mgCenter.themeSetName;
- else
- lable.text = @"默认";
- [cell.contentView addSubview:lable];
- [lable release];
- break;
- }
- default:
- break;
- }
- return cell;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIView *custom = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 38)] autorelease];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 38)];
- label.backgroundColor = [UIColor clearColor];
- NSArray *array = [NSArray arrayWithObjects:@"振动", @"声音",@"消息提醒设置",@"主题", nil];
- label.text = [array objectAtIndex:section];
- label.textAlignment = UITextAlignmentLeft;
- label.textColor = [UIColor whiteColor];
- label.font = [UIFont boldSystemFontOfSize:18];
- [custom addSubview:label];
- [label release];
- return custom;
- }
我定义四个单元将其填充到UITableView中。
当然我将UITableViewCell 实现以后,肯定希望在点击UITableViewCell 会处理什么事件
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- switch (cell.tag)
- {
- case 1:
- {
- break;
- }
- case 2:
- {
- break;
- }
- case 3:
- {
- if (themeControl == nil)
- {
- themeControl = [[ThemeViewController alloc] init];
- }
- [self.navigationController pushViewController:themeControl animated:YES];
- break;
- }
- default:
- break;
- }
- }
- Iphone之UITableView
- Iphone之UITableView
- [转载][Iphone]iOS UITableView之自定义UITableView
- iphone开发之UITableView 札记
- iphone/ipad开发之UITableView的方法
- iPhone开发技巧之私有API--- UITableView
- iPhone开发之UITableView详解(2)
- iPhone开发之UITableView入门2
- iphone开发之UITableView的使用
- iPhone UITableView
- iPhone开发技巧之私有API(2)— UITableView
- iPhone开发技巧之私有API(2)--- UITableView
- iPhone开发之UITableView简单应用(5)
- iphone开发之实现UITableView多选删除功能详解
- iphone开发之实现UITableView多选删除功能详解
- iphone开发之实现UITableView多选删除功能详解
- iPhone开发之实现UITableView多选删除功能详解
- iPhone开发之实现UITableView多选删除功能详解
- java.sql.SQLException: 关闭的连接
- 创建Struts 配置文件 (struts-config.xml)
- Android库项目的导出及其引用资源
- Data type conversions for API calls from Visual Basic
- 谈一谈我对java单继承和多继承的理解。
- Iphone之UITableView
- 跨域的理解与实现
- 【iOS-Cocos2d游戏开发之九】讲解CCSpriteBatchNode与TP工具的".pvr.ccz",".plist"共用的终极精灵优化及注意事项!
- ARRAYLIST VECTOR LINKEDLIST 区别与用法
- android系统学习(1)-ubuntu 11.10环境搭建
- 解决农业银行k宝在win7下不能用的问题
- Web框架自身安全
- Android HAL实现的三种方式(1) - 基于JNI的简单HAL设计
- 判断三点是否顺时针