亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

滑動以刪除并單擊“更多”按鈕(例如,在iOS 7上的Mail應用程序中)

滑動以刪除并單擊“更多”按鈕(例如,在iOS 7上的Mail應用程序中)

不負相思意 2019-12-07 14:51:10
用戶在表格視圖中滑動單元格時如何創建“更多”按鈕(如ios 7中的郵件應用程序)我一直在這里和Cocoa Touch論壇上都在尋找這些信息,但是我似乎找不到答案,我希望有一個比我自己更聰明的人給我解決方案。我希望當用戶滑動表格視圖單元格時,顯示多個編輯按鈕(他默認是刪除按鈕)。在iOS 7的郵件應用中,您可以滑動以刪除,但是會出現一個“更多”按鈕。
查看完整描述

3 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

我只是在Objective-C中添加以下內容,以使初學者(以及我們中那些拒絕學習Swift語法的人)更加清楚:


確保聲明uitableviewdelegate并具有以下方法:


?-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

?UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)

? ? {

? ? ? ? NSLog(@"Action to perform with Button 1");

? ? }];

? ? button.backgroundColor = [UIColor greenColor]; //arbitrary color

? ? UITableViewRowAction *button2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"Action to perform with Button2!");

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }];

? ? button2.backgroundColor = [UIColor blueColor]; //arbitrary color


? ? return @[button, button2]; //array with all the buttons you want. 1,2,3, etc...

}


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

// you need to implement this method too or nothing will work:


}

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

? ? {

? ? ? ? return YES; //tableview must be editable or nothing will work...

? ? }


查看完整回答
反對 回復 2019-12-07
?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

現在可以使用以下公共API來完成此操作:


func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {


? ? let moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "More", handler:{action, indexpath in

? ? ? ? print("MORE?ACTION");

? ? });

? ? moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);


? ? let deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete", handler:{action, indexpath in

? ? ? ? print("DELETE?ACTION");

? ? });


? ? return [deleteRowAction, moreRowAction];

}


查看完整回答
反對 回復 2019-12-07
  • 3 回答
  • 0 關注
  • 733 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號