{"id":6961,"date":"2025-05-31T14:43:38","date_gmt":"2025-06-05T06:47:38","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6961"},"modified":"2025-06-05T14:43:38","modified_gmt":"2025-06-05T06:47:38","slug":"https-badgameshow-com-steven-156","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-156\/","title":{"rendered":"Swift 2025\uff1a\u5b8c\u6574\u6559\u5b78\u5982\u4f55\u522a\u9664\u8207\u4fee\u6539 UITableView \u884c\ud83d\uddd1\ufe0f"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UITableView, \u522a\u9664, \u4fee\u6539\u884c, iOS \u958b\u767c\"><\/p>\n<h1>Swift 2025\uff1a\u5b8c\u6574\u6559\u5b78\u5982\u4f55\u522a\u9664\u8207\u4fee\u6539 UITableView \u884c\ud83d\uddd1\ufe0f<\/h1>\n<p>\u5728\u958b\u767c iOS App \u6642\uff0cUITableView \u662f\u4e00\u500b\u975e\u5e38\u5e38\u898b\u4e14\u91cd\u8981\u7684\u5143\u4ef6\uff0c\u5b83\u53ef\u4ee5\u8b93\u6211\u5011\u5feb\u901f\u5efa\u7acb\u5217\u8868\uff0c\u4f7f\u7528\u8005\u80fd\u5920\u66f4\u8f15\u9b06\u5730\u700f\u89bd\u8cc7\u6599\u3002\u672c\u7bc7\u6587\u7ae0\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 Swift \u4e2d\u522a\u9664\u548c\u4fee\u6539 UITableView \u7684\u884c\uff0c\u4e26\u63d0\u4f9b\u5be6\u4f5c\u7bc4\u4f8b\u8207\u6700\u4f73\u5be6\u8e10\uff0c\u5e6b\u52a9\u4f60\u63d0\u5347\u958b\u767c\u6548\u7387\u3002<\/p>\n<h2>\u522a\u9664 UITableView \u884c<\/h2>\n<p>\u8981\u522a\u9664 UITableView \u884c\uff0c\u6211\u5011\u9700\u8981\u5728 UITableView \u7684 delegate \u4e2d\u5be6\u4f5c <code>tableView(_:commit:forRowAt:)<\/code> \u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u66f4\u65b0\u5f8c\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff0c\u9069\u7528\u65bc Swift 2025\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {\n    if editingStyle == .delete {\n        \/\/ \u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u8cc7\u6599\u9663\u5217\n        myDataArray.remove(at: indexPath.row) \/\/ \u522a\u9664\u8cc7\u6599\n        tableView.deleteRows(at: [indexPath], with: .fade) \/\/ \u66f4\u65b0 UITableView\n    }\n}\n<\/code><\/pre>\n<p>\u7576\u4f7f\u7528\u8005\u9ede\u64ca\u522a\u9664\u6309\u9215\u6642\uff0c<code>tableView(_:commit:forRowAt:)<\/code> \u65b9\u6cd5\u6703\u88ab\u547c\u53eb\u3002\u5728\u6b64\u65b9\u6cd5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u57f7\u884c\u8cc7\u6599\u7684\u522a\u9664\u52d5\u4f5c\uff0c\u4f8b\u5982\u5f9e\u8cc7\u6599\u5eab\u4e2d\u522a\u9664\u8cc7\u6599\u6216\u662f\u5f9e\u9663\u5217\u4e2d\u79fb\u9664\u8cc7\u6599\u3002<\/p>\n<h2>\u4fee\u6539 UITableView \u884c<\/h2>\n<p>\u8981\u4fee\u6539 UITableView \u884c\uff0c\u6211\u5011\u9700\u8981\u5728 UITableView \u7684 delegate \u4e2d\u5be6\u4f5c <code>tableView(_:editActionsForRowAt:)<\/code> \u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u66f4\u65b0\u5f8c\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {\n    let editAction = UITableViewRowAction(style: .normal, title: \"Edit\") { (action, indexPath) in\n        \/\/ \u5be6\u4f5c\u4fee\u6539\u8cc7\u6599\u7684\u908f\u8f2f\n        \/\/ \u4f8b\u5982\u986f\u793a\u7de8\u8f2f\u756b\u9762\uff0c\u4e26\u66f4\u65b0\u8cc7\u6599\n    }\n    return [editAction]\n}\n<\/code><\/pre>\n<p>\u7576\u4f7f\u7528\u8005\u9ede\u64ca\u4fee\u6539\u6309\u9215\u6642\uff0c<code>tableView(_:editActionsForRowAt:)<\/code> \u65b9\u6cd5\u6703\u88ab\u547c\u53eb\u3002\u5728\u9019\u500b\u65b9\u6cd5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5be6\u4f5c\u986f\u793a\u7de8\u8f2f\u754c\u9762\u7684\u908f\u8f2f\uff0c\u4e26\u5c07\u4fee\u6539\u5f8c\u7684\u8cc7\u6599\u66f4\u65b0\u81f3\u8cc7\u6599\u5eab\u6216\u9663\u5217\u4e2d\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u5be6\u4f5c\u9019\u4e9b\u65b9\u6cd5\u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8211; **UITableView \u672a\u6b63\u78ba\u66f4\u65b0**\uff1a\u78ba\u4fdd\u5728\u522a\u9664\u6216\u4fee\u6539\u8cc7\u6599\u5f8c\uff0c\u6b63\u78ba\u8abf\u7528 <code>deleteRows(at:with:)<\/code> \u6216 <code>reloadData()<\/code> \u65b9\u6cd5\u3002<br \/>\n&#8211; **\u6309\u9215\u7121\u53cd\u61c9**\uff1a\u6aa2\u67e5 <code>editingStyle<\/code> \u662f\u5426\u6b63\u78ba\u8a2d\u7f6e\uff0c\u4e26\u78ba\u4fdd\u4f60\u7684 UITableView delegate \u5df2\u6b63\u78ba\u8a2d\u7f6e\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u522a\u9664\u548c\u4fee\u6539\u884c\uff0c\u4f60\u9084\u53ef\u4ee5\u8003\u616e\u5be6\u4f5c\u5176\u4ed6\u529f\u80fd\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8211; **\u79fb\u52d5\u884c**\uff1a\u5141\u8a31\u4f7f\u7528\u8005\u901a\u904e\u62d6\u52d5\u4f86\u91cd\u65b0\u6392\u5e8f UITableView \u7684\u884c\u3002<br \/>\n&#8211; **\u81ea\u5b9a\u7fa9\u7de8\u8f2f\u52d5\u4f5c**\uff1a\u70ba\u4e0d\u540c\u7684\u884c\u6dfb\u52a0\u4e0d\u540c\u7684\u7de8\u8f2f\u52d5\u4f5c\uff0c\u4ee5\u63d0\u4f9b\u66f4\u8c50\u5bcc\u7684\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u2013-UITableView-\u522a\u9664\uff0c\u4fee\u6539\u884c\ud83d\uddd1\ufe0f_1675399275.202667.webp\" alt=\"Swift \u2013 UITableView \u522a\u9664\uff0c\u4fee\u6539\u884c\ud83d\uddd1\ufe0f\" title=\"Swift, UITableView, \u522a\u9664, \u4fee\u6539, \u884c\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u5982\u4f55\u5728\u522a\u9664\u884c\u5f8c\u66f4\u65b0\u8cc7\u6599\u4f86\u6e90\uff1f<\/h3>\n<p>\u5728\u522a\u9664\u884c\u7684\u540c\u6642\uff0c\u52d9\u5fc5\u66f4\u65b0\u8cc7\u6599\u4f86\u6e90\uff0c\u5982\u9663\u5217\u6216\u8cc7\u6599\u5eab\uff0c\u4ee5\u78ba\u4fdd\u8cc7\u6599\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<h3>2. UITableView \u652f\u63f4\u54ea\u4e9b\u81ea\u5b9a\u7fa9\u52d5\u4f5c\uff1f<\/h3>\n<p>\u9664\u4e86\u522a\u9664\u548c\u7de8\u8f2f\uff0c\u4f60\u9084\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u7fa9\u52d5\u4f5c\uff0c\u5982\u5206\u4eab\u3001\u6a19\u8a18\u7b49\uff0c\u900f\u904e <code>tableView(_:editActionsForRowAt:)<\/code> \u65b9\u6cd5\u5be6\u73fe\u3002<\/p>\n<h3>3. \u5982\u4f55\u5728 UITableView \u4e2d\u6dfb\u52a0\u52d5\u756b\u6548\u679c\uff1f<\/h3>\n<p>\u4f7f\u7528 <code>tableView.deleteRows(at:with:)<\/code> \u65b9\u6cd5\u53ef\u4ee5\u70ba\u522a\u9664\u64cd\u4f5c\u6dfb\u52a0\u52d5\u756b\u6548\u679c\uff0c\u589e\u5f37\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728Swift\u4e2d\u4f7f\u7528UITableView\u522a\u9664\u548c\u4fee\u6539\u884c\u7684\u65b9\u6cd5\uff0c\u4e26\u63d0\u4f9b\u7c21\u55ae\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n","protected":false},"author":1,"featured_media":6959,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-6961","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u2013-UITableView-\u522a\u9664\uff0c\u4fee\u6539\u884c\ud83d\uddd1\ufe0f_1675399275.202667.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Oh","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6961"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6961\/revisions"}],"predecessor-version":[{"id":13591,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6961\/revisions\/13591"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6959"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}