为什么我写删除UITableView行的代理时云天化他盛华出了问题题

用户名:Super_linux
文章数:54
访问量:5650
注册日期:
阅读量:1297
阅读量:3317
阅读量:432168
阅读量:1120148
51CTO推荐博文
//设置行高- (CGFloat)tableView:(UITableView&*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{&&&&&&&return&80;}//分区- (NSInteger)numberOfSectionsInTableView:(UITableView&*)tableView{&&&&// Return the number of sections.&&&&return&3;}//设置每个区有多少行共有多少行- (NSInteger)tableView:(UITableView&*)tableView numberOfRowsInSection:(NSInteger)section{&&&&return&2;}//设置区域的名称- (NSString&*)tableView:(UITableView&*)tableView titleForHeaderInSection:(NSInteger){&&&return&@"123";}//是否允许行移动-(BOOL)tableView:(UITableView&*)tableView canMoveRowAtIndexPath:(NSIndexPath&*)indexPath{&&&&&&&&return YES;}//响应点击事件- (void)tableView:(UITableView&*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{&&&&NSLog(@"响应单击事件");}//小按钮的响应事件- (void)tableView:(UITableView&*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath&*)indexPath{&&&&NSLog(@"accessoryButton的响应事件"); &&&&&}//删除按钮的名字-(NSString*)tableView:(UITableView&*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath&*)indexPath{&&&&return&@"删除";}//设置滑动,-(BOOL)tableView:(UITableView&*)tableView canEditRowAtIndexPath:(NSIndexPath&*)indexPath{&&&&//ruturn NO不实现滑动&&&&return YES;}-(UITableViewCellEditingStyle)tableView:(UITableView&*)tableView editingStyleForRowAtIndexPath:(NSIndexPath&*)indexPath{&&&&NSLog(@"手指撮动了");&&&&return&UITableViewCellEditingStyleDelete;//&&&&//插入//&&&&return UITableViewCellEditingStyleI}设置CELL的样式&&&&//&&&&&&&&cell.selectionStyle = UITableViewCellSelectionStyleB&&&&&&&&//灰色//&&&&cell.selectionStyle = UITableViewCellSelectionStyleG&&&&&&&&//无颜色//&&&&&&&&cell.selectionStyle = UITableViewCellSelectionStyleN&&&&&&&&//向右箭头样式//&&&&&&&&cell.accessoryType = UITableViewCellAccessoryDisclosureI&&&&&&&&//向右箭头button&&&&&&&&&&&cell.accessoryType&=&UITableViewCellAccessoryDetailDisclosureButton;&UITableViewCellStyleDefault,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x)&&&&UITableViewCellStyleValue1,// Left aligned label on left and right aligned label on right with blue text (Used in Settings)&&&&UITableViewCellStyleValue2,// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)&&&&UITableViewCellStyleSubtitle本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)今天看啥 热点:
UITableView的点击删除或者插入一条Cell,uitableviewcell
& & 最近在实现UITableView的编辑cell功能时,发现有些淡忘这一块东西了.所以,姑且写一篇博客复习一下这块的知识吧.本文主要拿删除cell来讲,插入其实一模一样,就不单独说了.
& &删除cell,就我目前遇到的来说,主要由两种,一种是侧滑删除cell,还有一种就是点击删除cell.侧滑删除,想必大家一定很熟悉,今天我主要说说点击删除.如下图:
这样的点击删除cell,我第一次看,觉得很简单,就是发送一条请求,删除这条数据,然后刷新一下UITableView就好了.但是当我这样写了,却发现错了.
然后我才发现自己想错了.我们在实现侧滑删除的时候,一般都是在下面这个代理方法中,先删除数据源,然后在删除cell.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
[tableView beginUpdates];
&if (editingStyle ==UITableViewCellEditingStyleDelete) {
& & & & NSLog(@&删除&);
& & & & //第一,删除数据源,
& & & & [_arrremoveObject:_arr[indexPath.row]];
& & & & //第二,删除表格cell
//& & & & [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
& & & & & & [tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:
UITableViewRowAnimationRight];
& & }else{
& & & & //第一,插入数据源
& & & & [_arrinsertObject:@&张三&atIndex:indexPath.row];
& & & &//第二,插入cell.
& & & & [tableView insertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationLeft];
& & & & NSLog(@&添加&);
&& & [tableView endUpdates];
我现在要实现的功能其实跟侧滑删除一样,也不所以我也要做上面的操作,先删除数据源,然后再删除cell.然后我还要做的是发送请求,后台删除,数据库中的这一条数据,跟我前端上面保持一致.
我想明白了,然后剩下的就是编码了.下面是部分源码
#pragma mark ------- UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
& & MDWGirlInfoViewController *viewController = (MDWGirlInfoViewController *)self.controller;
& & MDWFocusRequest *request=[[MDWFocusRequestalloc]
& & MDWRequestManager *manager=[MDWRequestManagermanager];
& & if (buttonIndex ==1) {
& & NSString * path = [@&/status/&stringByAppendingString:_statusId];
& & //第一步,先发送网络请求删除数据
& & [manager sendWithoutResponseRequest:pathmethod:@&DELETE&paras:nilbody:request
onSuccess:^(AFHTTPRequestOperation *operartion,id responseObject) {
& &//第二步,删除数据源
& &&NSMutableArray *mutableArray=[NSMutableArrayarrayWithArray:_modelData];
& & [mutableArray removeObjectAtIndex:[indexPathrow]];
& & _modelData=[NSArrayarrayWithArray:mutableArray];
& &//第三步,删除cell
&&[self.tableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
& & } onFailure:^(AFHTTPRequestOperation *operation,NSError *error) {
在UITableView中插入或者删除指定的行(或者节)使用的是如下几个API:
insertRowsAtIndexPath: withRowAnimation: 在指定位置插入行deleteRowsAtIndexPath: withRowAnimation: 删除指定行insertSections: withRowAnimation: 在指定位置插入节deleteSections: withRowAnimation: 删除指定节
好了,按照这样写完,就搞定这个功能了,原谅我就不举例插入cell了.原理跟删除cell一样.......
相关搜索:
相关阅读:
相关频道:
Android教程最近更新UITableView删除行和行排序这里只介绍代理方法_iOS开发_动态网站制作指南
UITableView删除行和行排序这里只介绍代理方法
来源:人气:413
#agma mark -代理方法
#pragma mark 设置cell表格高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
& & return 60;
#pragma mark 当cell实行编辑功能时调用
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
& & if(editingStyle!=UITableViewCellEditingStyleDelete)
& & //1.删除数据源数据
& & [_persons removeObject:_persons[indexPath.row]];
& & //2.重新加载数据
&& [self.tableView reloadData];
#pragma mark 当cell实行排序功能时调用
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
& & //1 拿出要移动的数据,并删除
& & Person *p=_persons[sourceIndexPath.row];
& & [_persons removeObject:p];
& & //2 把要移动的数据添加到目的位置
& & [_persons insertObject:p atIndex:destinationIndexPath.row];
#pragma mark 监听删除按钮
- (IBAction)remove:(UIBarButtonItem *)sender {
// & & self.tableView.editing=YES;//进入编辑模式
& & BOOL result=!self.tableView.isE
& & [self.tableView setEditing:result animated:YES];
优质网站模板页面已拦截
无锡网警提示您:
该网站已被大量用户举报,可能存在安全漏洞且已被黑客利用,企图通过虚假登录框盗取QQ帐号。

我要回帖

更多关于 云天化刘勇出了问题 的文章

 

随机推荐