网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

IOS--添加底部工具栏和UITableViewCell的滑动删除-创新互联

添加底部工具栏和UITableViewCell的滑动删除

目前创新互联已为上1000+的企业提供了网站建设、域名、虚拟主机、网站托管、服务器租用、企业网站设计、凤冈网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

一.添加底部工具栏

在工具栏上设置图标时可以使用系统自带图标也可以使用自定义图标,下面分别介绍这两种方法:

1.使用系统自带图标(编辑图标)

UIBarButtonItem *editItem = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemComposetarget:selfaction:@selector(editEventClick)];

2.使用自定义图标(删除图标)

UIBarButtonItem *deleteItem = [[UIBarButtonItemalloc] initWithImage:[UIImagep_w_picpathNamed:@"ic_delete.png"] style:UIBarButtonItemStylePlaintarget:selfaction:@selector(deleteEventClick)];

工具栏提示:

1.固定空间可以拥有宽度-----在所有UIBarButtonItem’中,只有UIBarButtonSystemItemFixedSpace条目可以被分配一个宽度,因此,创建空间条目,设置其宽度,然后在将其添加到条目列中。

UIBarButtonItem *fixItem1 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpacetarget:nilaction:nil];

fixItem1.width = 125;

   NSArray *arrayItem = [NSArrayarrayWithObjects:fixItem1,     editItem,fixItem2,deleteItem,nil];

   [selfsetToolbarItems:arrayItem];

此处编辑图标是自定义的图片,删除图标是系统自带,在截图中可以看出二者的区别

运行之后效果图如下:

IOS--添加底部工具栏和UITableViewCell的滑动删除

2.使用一个灵活空间进行左或右对齐-----在条目列表中开始添加一个’ UIBarButtonSystemITemFlexibleSpace会使所有剩余条目右对齐。在末尾添加一个,则左对齐,使用两个UIBarButtonSystemItemFlexibleSpace,一个在开头,一个添加在末尾,会使剩余条目居中对齐。

UIBarButtonItem *fixItem1 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil];

    NSArray *arrayItem = [NSArrayarrayWithObjects:fixItem1,deleteItem,fixItem2,editItem,fixItem2,nil];

    [selfsetToolbarItems:arrayItem];

    运行之后效果图如下:

   IOS--添加底部工具栏和UITableViewCell的滑动删除

  (此处编辑图标和删除图标都是系统自带)

二.滑动删除

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

returnYES;

}

//定义编辑样式

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableVieweditingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

returnUITableViewCellEditingStyleDelete;

}

//进入编辑模式

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath:(NSIndexPath *)indexPath {

//code

}

启用上面两个代理,并增加数据删除操作:

运行之后效果如下:

IOS--添加底部工具栏和UITableViewCell的滑动删除

若让其左滑删除,则:(核心代码如下)

//取消TableView的右滑,保留左滑

  UISwipeGestureRecognizer *swipeRight =[[UISwipeGestureRecognizer alloc]initWithTarget:self action:nil];

  swipeRight.direction =UISwipeGestureRecognizerDirectionRight;

  [self. tableView addGestureRecognizer:swipeRight];

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


名称栏目:IOS--添加底部工具栏和UITableViewCell的滑动删除-创新互联
文章网址:http://bjjierui.cn/article/csohjc.html

其他资讯