iOS开发笔记-UITableView的单选
来源:互联网 发布:php和java哪个好找工作 编辑:程序博客网 时间:2024/05/01 01:55
好吧,很久以前写的,现在把它整理出来给那些需要的人
//
// JPViewController.m
// SingleSelectedDemo
//
// Created by kuaitu on 15/1/9.
// Copyright (c) 2015年 JP. All rights reserved.
//
#import "JPViewController.h"
@interfaceJPViewController ()
@end
@implementation JPViewController
{
int _row;
int _rowNum;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//记录上次选择的结果
NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"select"];
_row = [str intValue];
UITableView *tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)style:UITableViewStyleGrouped];
tableView.delegate =self;
tableView.dataSource = self;
[self.viewaddSubview:tableView];
}
#pragma mark - UITableViewDatasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.tintColor = [UIColor redColor];
if ( _rowNum == indexPath.row)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.textLabel.text = @"111";
return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"111111");
_rowNum = indexPath.row;
[tableView reloadData];
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%d",indexPath.row] forKey:@"select"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- iOS开发笔记-UITableView的单选
- IOS开发笔记-UITableView的多选
- iOS开发笔记之UITableView的使用
- [ios] UITableVIew单选效果
- iOS学习 UITableView 单选
- iOS开发学习笔记 UITableview
- iOS中UITableView单选标记的实现
- iOS开发笔记>> UIButton与UITableView的层级结构
- iOS开发笔记>> 简述UItableView 的复用机制
- 【iOS开发】UITableView的使用
- 【iOS】UITableView Cell自定义单选功能
- iOS开发学习笔记——UITableview
- iOS开发笔记--UITableView入门
- IOS开发笔记30-UITableView(1)
- IOS开发笔记31-UITableView(2)
- IOS开发笔记32-UITableView(3)
- IOS开发笔记33-UITableView(1)
- iOS单选——UITableView 写的列表单选
- hoyi-web[java] 用户控件的使用
- 基于Ubuntu14.04的Hadoop2.6.0完全分布式安装
- 单源最短路-SPFA(poj2387)
- AngularJS中$http.jsonp跨域请求问题
- UIColor (16进制颜色、透明色使用)
- iOS开发笔记-UITableView的单选
- (几个gradle)gradle工程的环境搭建----安装gradle
- AKKA文档(java版)—角色
- Spring Security3 - MVC 整合教程 (初识Spring Security3)
- 用NPOI操作EXCEL-锁定列CreateFreezePane()
- oracle分页sql
- 36,const的作用
- 【HTML5】触摸事件(touchstart、touchmove和touchend)
- 公元2015年11月25日。阴。