- 浏览: 545595 次
- 性别:
- 来自: 石家庄
文章分类
最新评论
-
toyota2006:
thank you!
适配器(Adapter)模式 -
910014107:
收藏一下
JIRA安装和破解 -
wangchaobashen:
注册完是一年期的License,请问这个期限该如何修改呢?
JIRA安装和破解 -
ihqn19:
总而言之,就是不知道你想表达什么就对了。
JS 面向对象的简单应用实例 -
jxls162408:
第四步更新tomcat libraris ,找不到那个包呀。怎 ...
JIRA安装和破解
可编辑的TableView
在编写简单的导航控制器基础上,让TableView的条目是可编辑的。这里示例将实现对条目的排序,删除等类似。实现的效果:
在编写简单的导航控制器基础上做如下修改。
首先要将存储数据的NSArray改为NSMutableArray,因为前者是不可变的。在头文件中:
@interface RootViewController : UITableViewController <UITableViewDelegate,UITableViewDataSource>{
NSMutableArray *dataItems;
在m文件中:
dataItems= [[NSMutableArray alloc] initWithObjects:@"张三",@"李四",nil];
然后,增加导航条右侧的按钮。先写出点击按钮的函数:
-(IBAction)toggleMove{
[self.tableView setEditing:!self.tableView.editing animated:YES];
}
下面,声明按钮并关联上述函数:
- (void)viewDidLoad {
dataItems= [[NSMutableArray alloc] initWithObjects:@"张三",@"李四",nil];
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"移动"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(toggleMove)];
[super viewDidLoad];
}
其实就是增加一句话。
添加有关显示风格等的函数:
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
其中,后者(canMoveRowAtIndexPath)如果不写,将是删除而不是移动。
在原有生成表条目的函数中增加一句话,用于显示右侧的控件:
- (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] autorelease];
cell.showsReorderControl=YES;
}
下面是最关键的函数,在移动表条目时回调的函数:
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *) fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath{
id object=[[dataItems objectAtIndex:[fromIndexPath row]] retain];
[dataItems removeObjectAtIndex:[fromIndexPath row]];
[dataItems insertObject:object atIndex:[toIndexPath row]];
[object release];
}
这样就可以实现上述的效果了,不过会出现这样的警告日志:
2010-10-13 22:42:47.220 NavTest[77449:207] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <RootViewController: 0x5c04150>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
因为accessoryTypeForRowWithIndexPath函数已经不建议使用了,要替换成:
// Customize the appearance of table view cells.
- (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] autorelease];
cell.showsReorderControl=YES;
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
}
NSUInteger row=[indexPath row];
cell.textLabel.text=[dataItems objectAtIndex:row];
return cell;
}
同时删除tableView:accessoryTypeForRowWithIndexPath函数。这个问题不是编辑TableView时出现的
在编写简单的导航控制器基础上,让TableView的条目是可编辑的。这里示例将实现对条目的排序,删除等类似。实现的效果:
在编写简单的导航控制器基础上做如下修改。
首先要将存储数据的NSArray改为NSMutableArray,因为前者是不可变的。在头文件中:
@interface RootViewController : UITableViewController <UITableViewDelegate,UITableViewDataSource>{
NSMutableArray *dataItems;
在m文件中:
dataItems= [[NSMutableArray alloc] initWithObjects:@"张三",@"李四",nil];
然后,增加导航条右侧的按钮。先写出点击按钮的函数:
-(IBAction)toggleMove{
[self.tableView setEditing:!self.tableView.editing animated:YES];
}
下面,声明按钮并关联上述函数:
- (void)viewDidLoad {
dataItems= [[NSMutableArray alloc] initWithObjects:@"张三",@"李四",nil];
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"移动"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(toggleMove)];
[super viewDidLoad];
}
其实就是增加一句话。
添加有关显示风格等的函数:
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
其中,后者(canMoveRowAtIndexPath)如果不写,将是删除而不是移动。
在原有生成表条目的函数中增加一句话,用于显示右侧的控件:
- (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] autorelease];
cell.showsReorderControl=YES;
}
下面是最关键的函数,在移动表条目时回调的函数:
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *) fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath{
id object=[[dataItems objectAtIndex:[fromIndexPath row]] retain];
[dataItems removeObjectAtIndex:[fromIndexPath row]];
[dataItems insertObject:object atIndex:[toIndexPath row]];
[object release];
}
这样就可以实现上述的效果了,不过会出现这样的警告日志:
2010-10-13 22:42:47.220 NavTest[77449:207] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <RootViewController: 0x5c04150>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
因为accessoryTypeForRowWithIndexPath函数已经不建议使用了,要替换成:
// Customize the appearance of table view cells.
- (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] autorelease];
cell.showsReorderControl=YES;
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
}
NSUInteger row=[indexPath row];
cell.textLabel.text=[dataItems objectAtIndex:row];
return cell;
}
同时删除tableView:accessoryTypeForRowWithIndexPath函数。这个问题不是编辑TableView时出现的
发表评论
-
画板使用
2011-04-13 15:46 3318Painting.h #import <UIKit/UI ... -
UIImage应用与内存管理
2011-03-24 10:44 4026用UIImage加载图像的方法很多,最常用的是下面两种: ... -
NSMutableArray与NSArray的区别
2011-03-21 16:05 24491: NSMutableArray能添加、插入、删除对象,而 ... -
iPhone/iPad 开发:录音及声音播放
2011-01-21 15:30 4675-(IBAction) recordOrStop: (id) ... -
iphone/ipad开发:编写声控红旗飘飘
2011-01-21 15:24 1468见附件Flag.zip -
TableView 的使用 实例二
2010-12-14 16:06 20692在实例一我们做了一个最基本的导航列表(其实还没有导航功能,只不 ... -
TableView 的使用 实例一
2010-12-14 13:45 10373TableView 是iphone/ipad中常常会用到的导航 ... -
iPhone/iPad 开发: 解析本地/网络上的xml文件(实例建附件)
2010-11-16 11:46 49011、解析本地xml文件 //找到本地test.xml文件 ... -
iPhone/iPad 开发: Objective-C 接分字符串成数组(类似java 的 split)
2010-11-11 14:46 6757在很多语言如 java , ruby , python中都有将 ... -
iPhone/iPad SQLite3 简明 使用 实例
2010-11-02 11:54 6797简单sqlite使用 sqlite是嵌入式的和轻量级的sql数 ... -
iPhone/iPad Timer 使用
2010-10-22 16:54 1831//以下代码为每隔1.5秒执行一次autoPlay函数 [ ... -
视图翻转问题
2010-10-22 16:47 1574//实现shouldAutorotateToInterface ... -
解决子view被ViewController遮挡的问题
2010-10-22 16:42 2112ViewController在加载子View的时候会出现子Vi ... -
iPhone/iPad 动画效果切换画面
2010-10-22 11:48 3350iPhone/iPad 动画效果切换画面 -(void)s ... -
内存管理总结
2010-10-22 11:40 1190iPhone系统中的Objective-C的内存管理机制是 ... -
iPhone/iPad 读写 Plist文件
2010-10-22 11:36 4807iPhone/iPad 读写 Plist文件 1.写Pli ... -
iPhone开发经典语录集锦
2010-10-22 11:21 1119引用1:如果无法保证子类行为的一致性,那么就用委托 If t ... -
深入理解iPhone委托模式兼谈iPhone生命周期
2010-10-22 11:10 2578深入理解iPhone委托模式兼谈iPhone生命周期 本文转载 ... -
得到application对象
2010-10-22 10:56 967application=[UIApplication shar ... -
iPhone/iPad程序 点击 休眠键委托事件 和 唤醒后的响应事件
2010-10-13 17:03 1979//休眠后委托事件 - (void)application ...
相关推荐
实现单元格可移动的列表。用户可以移动列表中任意单元格,从而改变单元格的顺序。用户移动过程中不需要让列表处于可编辑模式(edit mode)。仅支持IOS5.0。 注意:请在Mac下解压使用
本 Demo 仿造了美团外卖和礼物说,分别实现了两个 TableView 之间和 TableView 与 CollectionView 之间的联动效果,效果见 gif 图。 由于工程的文件比较大,代码传不上去,超过了大小。 【GitHub - OC版本】下载...
自定义UITableViewCell。实现在列表上加入各种徽章(badgeString)效果。比如加上有背景颜色的数字等等。 注意:请在Mac下解压使用
在弹出对话框(Alert dialogue)中加入列表(UITableView)。 注意:请在Mac下解压使用
自定义UITableViewCell。列表初始只显示一定数量的行(cell),点击“显示更多(show more)”按钮,列表将动态增加新行,从而显示更多内容。 注意:请在Mac下解压使用
自定义UITableViewCell。实现的效果是,用户用手指划过列表中的任意一行,此行会有“撕开”的效果,显示更多的按钮信息,用户手指再次划过,则复原。 注意:请在Mac下解压使用
实现水平方向的列表效果。即列表是左右滚动,而不是上下滚动。 注意:请在Mac下解压使用
实现具有多列的列表,可用于表格界面。 注意:请在Mac下解压使用
在UIScrollView中加入多个UITableView。 注意:请在Mac下解压使用
手指拖拉/拖拽/往下拉动列表更新列表内容。 注意:请在Mac下解压使用
[self setupEmpty:self.tableView]; [self setupRefresh:self.tableView option:ATRefreshNone]; [self headerRefreshing]; 2、下拉刷新 [self setupEmpty:self.tableView]; [self setupRefresh:self....
iphone开发TableView编辑 不错的学习资料
在iPhone上实现iPad上UIPopoverController的效果,也就是,点击选中列表某一行,将弹出另外一个小列表,显示更多的内容。 注意:请在Mac下解压使用
自定义UITableViewCell。列表初始只显示一定数量的行(cell),点击“显示更多(show more)”按钮,列表将动态增加新行,从而显示更多内容。 注意:请在Mac下解压使用
自定义UITableViewCell。实现各种样式的TableView输入界面。包括登录界面(login),在列表行中加入各式各样的控件。 注意:请在Mac下解压使用
自定义UITableViewCell。实现各种样式的表格输入界面。在列表单元中加入各式各样的控件,比如Switch,Slider, TextField等等,用于应用内的各种设置效果。也可以自定义segment header。 注意:请在Mac下解压使用