IOS--添加底部工具欄和UITableViewCell的滑動刪除

添加底部工具欄和UITableViewCell的滑動刪除

創(chuàng)新互聯(lián)為客戶提供專業(yè)的成都網(wǎng)站設(shè)計、網(wǎng)站制作、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開發(fā). 服務(wù)項目涵蓋了網(wǎng)頁設(shè)計、網(wǎng)站程序開發(fā)、WEB系統(tǒng)開發(fā)、微信二次開發(fā)、移動網(wǎng)站建設(shè)等網(wǎng)站方面業(yè)務(wù)。

一.添加底部工具欄

在工具欄上設(shè)置圖標(biāo)時可以使用系統(tǒng)自帶圖標(biāo)也可以使用自定義圖標(biāo),下面分別介紹這兩種方法:

1.使用系統(tǒng)自帶圖標(biāo)(編輯圖標(biāo))

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

2.使用自定義圖標(biāo)(刪除圖標(biāo))

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

工具欄提示:

1.固定空間可以擁有寬度-----在所有UIBarButtonItem’中,只有UIBarButtonSystemItemFixedSpace條目可以被分配一個寬度,因此,創(chuàng)建空間條目,設(shè)置其寬度,然后在將其添加到條目列中。

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

fixItem1.width = 125;

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

      [selfsetToolbarItems:arrayItem];

此處編輯圖標(biāo)是自定義的圖片,刪除圖標(biāo)是系統(tǒng)自帶,在截圖中可以看出二者的區(qū)別

運(yùn)行之后效果圖如下:

IOS--添加底部工具欄和UITableViewCell的滑動刪除

2.使用一個靈活空間進(jìn)行左或右對齊-----在條目列表中開始添加一個’ UIBarButtonSystemITemFlexibleSpace會使所有剩余條目右對齊。在末尾添加一個,則左對齊,使用兩個UIBarButtonSystemItemFlexibleSpace,一個在開頭,一個添加在末尾,會使剩余條目居中對齊。

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

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

       [selfsetToolbarItems:arrayItem];

        運(yùn)行之后效果圖如下:

     IOS--添加底部工具欄和UITableViewCell的滑動刪除

   (此處編輯圖標(biāo)和刪除圖標(biāo)都是系統(tǒng)自帶)

二.滑動刪除

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

{

returnYES;

}

//定義編輯樣式

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

{

returnUITableViewCellEditingStyleDelete;

}

//進(jìn)入編輯模式

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

//code

}

啟用上面兩個代理,并增加數(shù)據(jù)刪除操作:

運(yùn)行之后效果如下:

IOS--添加底部工具欄和UITableViewCell的滑動刪除

若讓其左滑刪除,則:(核心代碼如下)

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

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

   swipeRight.direction =UISwipeGestureRecognizerDirectionRight;

   [self. tableView addGestureRecognizer:swipeRight];

網(wǎng)站標(biāo)題:IOS--添加底部工具欄和UITableViewCell的滑動刪除
分享路徑:http://bm7419.com/article34/pcegpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄外貿(mào)網(wǎng)站建設(shè)、面包屑導(dǎo)航、電子商務(wù)、用戶體驗動態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)