Swift Multi Selection TableView occurs error while unselecting rowsChange second table content based on first table row selected in swiftHow to detect tableView cell touched or clicked in swiftSending data to a new view controller through didselectrowatindexpathUpdate or reload UITableView after completion of delete action on detail viewthread 1: exc_bad_instruction(code=exc_1386_invop,subcode=0x0)How do I make my table view's cell selection based on a stepper value, not the physical selection of the cell in swift 3?Make (first) row unselectable in pickerview (Swift 3, Xcode)How Can I Fetch Sub Category From Rest Api(Restkit) Using Expandable Tableview Cell Swift 3How to implement one select/deselect all button while above tableview in objective c?Cannot assign value of type 'String?' to type 'CBPeripheral?'

xcolor breaking ligatures

Why does Bran want to find Drogon?

Dad jokes are fun

What does it mean when a vocal teacher tell you that your lowest notes are heavy?

One word for 'the thing that attracts me'?

Variable declaraton with extra in C

Does French have the English "short i" vowel?

Expected maximum number of unpaired socks

Why is the Eisenstein ideal paper so great?

Why does the hash of infinity have the digits of π?

What weight should be given to writers groups critiques?

What is the recommended procedure to land a taildragger in a crosswind?

...And they were stumped for a long time

Apart from the sine wave, are there any other waveshapes that could be thought of as commonly appearing "in nature"?

How to keep consistency across the application architecture as a team grows?

Is this homebrew "Cactus Grenade" cantrip balanced?

Can we assume that a hash function with high collision resistance also means highly uniform distribution?

Why did Jon Snow admit his fault in S08E06?

Why does the Starter Set wizard have six spells in their spellbook?

How to let other coworkers know that I don't share my coworker's political views?

Why sampling a periodic signal doesn't yield a periodic discrete signal?

Testing using real data of the customer

Can a UK national work as a paid shop assistant in the USA?

Why was this character made Grand Maester?



Swift Multi Selection TableView occurs error while unselecting rows


Change second table content based on first table row selected in swiftHow to detect tableView cell touched or clicked in swiftSending data to a new view controller through didselectrowatindexpathUpdate or reload UITableView after completion of delete action on detail viewthread 1: exc_bad_instruction(code=exc_1386_invop,subcode=0x0)How do I make my table view's cell selection based on a stepper value, not the physical selection of the cell in swift 3?Make (first) row unselectable in pickerview (Swift 3, Xcode)How Can I Fetch Sub Category From Rest Api(Restkit) Using Expandable Tableview Cell Swift 3How to implement one select/deselect all button while above tableview in objective c?Cannot assign value of type 'String?' to type 'CBPeripheral?'






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















i have a problem with my multi selection table view. I receive an error if i unselect the previous select rows with an different order than i have selected it. It says




Index out of range
I receive this error while i'm trying to remove an item of my array. Here is my Code:




 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCell.AccessoryType.checkmark
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.none
//Line above occurs the error
checkedCategories.remove(at: indexPath.row)
else
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.checkmark
checkedCategories.append(allcategories[indexPath.row])











share|improve this question






















  • Show declaration of checkedCategories. Is it set or array?

    – ManWithBear
    Mar 23 at 23:44












  • yes, it is a Array[Object]

    – Markus Gerlach
    Mar 24 at 8:38

















-2















i have a problem with my multi selection table view. I receive an error if i unselect the previous select rows with an different order than i have selected it. It says




Index out of range
I receive this error while i'm trying to remove an item of my array. Here is my Code:




 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCell.AccessoryType.checkmark
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.none
//Line above occurs the error
checkedCategories.remove(at: indexPath.row)
else
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.checkmark
checkedCategories.append(allcategories[indexPath.row])











share|improve this question






















  • Show declaration of checkedCategories. Is it set or array?

    – ManWithBear
    Mar 23 at 23:44












  • yes, it is a Array[Object]

    – Markus Gerlach
    Mar 24 at 8:38













-2












-2








-2








i have a problem with my multi selection table view. I receive an error if i unselect the previous select rows with an different order than i have selected it. It says




Index out of range
I receive this error while i'm trying to remove an item of my array. Here is my Code:




 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCell.AccessoryType.checkmark
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.none
//Line above occurs the error
checkedCategories.remove(at: indexPath.row)
else
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.checkmark
checkedCategories.append(allcategories[indexPath.row])











share|improve this question














i have a problem with my multi selection table view. I receive an error if i unselect the previous select rows with an different order than i have selected it. It says




Index out of range
I receive this error while i'm trying to remove an item of my array. Here is my Code:




 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCell.AccessoryType.checkmark
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.none
//Line above occurs the error
checkedCategories.remove(at: indexPath.row)
else
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCell.AccessoryType.checkmark
checkedCategories.append(allcategories[indexPath.row])








ios swift






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 23:33









Markus GerlachMarkus Gerlach

365




365












  • Show declaration of checkedCategories. Is it set or array?

    – ManWithBear
    Mar 23 at 23:44












  • yes, it is a Array[Object]

    – Markus Gerlach
    Mar 24 at 8:38

















  • Show declaration of checkedCategories. Is it set or array?

    – ManWithBear
    Mar 23 at 23:44












  • yes, it is a Array[Object]

    – Markus Gerlach
    Mar 24 at 8:38
















Show declaration of checkedCategories. Is it set or array?

– ManWithBear
Mar 23 at 23:44






Show declaration of checkedCategories. Is it set or array?

– ManWithBear
Mar 23 at 23:44














yes, it is a Array[Object]

– Markus Gerlach
Mar 24 at 8:38





yes, it is a Array[Object]

– Markus Gerlach
Mar 24 at 8:38












1 Answer
1






active

oldest

votes


















0














You always adding items in the end of array (so index of added item is checkedCategories.count - 1). But deleting by index of row.

So instead of row index, get index of added category and then remove by this index



if let index = checkedCategories.firstIndex(of: allcategories[indexPath.row]) 
checkedCategories.remove(at: index)






share|improve this answer























  • Hey, i cannot use this code, xcode is throwing different errors.

    – Markus Gerlach
    Mar 24 at 8:39











  • Maybe its because it is checkedCategories is [SellerObject]

    – Markus Gerlach
    Mar 24 at 9:10











  • @MarkusGerlach perhaps you could share what errors it throwing?

    – ManWithBear
    Mar 24 at 11:06











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319354%2fswift-multi-selection-tableview-occurs-error-while-unselecting-rows%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You always adding items in the end of array (so index of added item is checkedCategories.count - 1). But deleting by index of row.

So instead of row index, get index of added category and then remove by this index



if let index = checkedCategories.firstIndex(of: allcategories[indexPath.row]) 
checkedCategories.remove(at: index)






share|improve this answer























  • Hey, i cannot use this code, xcode is throwing different errors.

    – Markus Gerlach
    Mar 24 at 8:39











  • Maybe its because it is checkedCategories is [SellerObject]

    – Markus Gerlach
    Mar 24 at 9:10











  • @MarkusGerlach perhaps you could share what errors it throwing?

    – ManWithBear
    Mar 24 at 11:06















0














You always adding items in the end of array (so index of added item is checkedCategories.count - 1). But deleting by index of row.

So instead of row index, get index of added category and then remove by this index



if let index = checkedCategories.firstIndex(of: allcategories[indexPath.row]) 
checkedCategories.remove(at: index)






share|improve this answer























  • Hey, i cannot use this code, xcode is throwing different errors.

    – Markus Gerlach
    Mar 24 at 8:39











  • Maybe its because it is checkedCategories is [SellerObject]

    – Markus Gerlach
    Mar 24 at 9:10











  • @MarkusGerlach perhaps you could share what errors it throwing?

    – ManWithBear
    Mar 24 at 11:06













0












0








0







You always adding items in the end of array (so index of added item is checkedCategories.count - 1). But deleting by index of row.

So instead of row index, get index of added category and then remove by this index



if let index = checkedCategories.firstIndex(of: allcategories[indexPath.row]) 
checkedCategories.remove(at: index)






share|improve this answer













You always adding items in the end of array (so index of added item is checkedCategories.count - 1). But deleting by index of row.

So instead of row index, get index of added category and then remove by this index



if let index = checkedCategories.firstIndex(of: allcategories[indexPath.row]) 
checkedCategories.remove(at: index)







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 23 at 23:49









ManWithBearManWithBear

1,854720




1,854720












  • Hey, i cannot use this code, xcode is throwing different errors.

    – Markus Gerlach
    Mar 24 at 8:39











  • Maybe its because it is checkedCategories is [SellerObject]

    – Markus Gerlach
    Mar 24 at 9:10











  • @MarkusGerlach perhaps you could share what errors it throwing?

    – ManWithBear
    Mar 24 at 11:06

















  • Hey, i cannot use this code, xcode is throwing different errors.

    – Markus Gerlach
    Mar 24 at 8:39











  • Maybe its because it is checkedCategories is [SellerObject]

    – Markus Gerlach
    Mar 24 at 9:10











  • @MarkusGerlach perhaps you could share what errors it throwing?

    – ManWithBear
    Mar 24 at 11:06
















Hey, i cannot use this code, xcode is throwing different errors.

– Markus Gerlach
Mar 24 at 8:39





Hey, i cannot use this code, xcode is throwing different errors.

– Markus Gerlach
Mar 24 at 8:39













Maybe its because it is checkedCategories is [SellerObject]

– Markus Gerlach
Mar 24 at 9:10





Maybe its because it is checkedCategories is [SellerObject]

– Markus Gerlach
Mar 24 at 9:10













@MarkusGerlach perhaps you could share what errors it throwing?

– ManWithBear
Mar 24 at 11:06





@MarkusGerlach perhaps you could share what errors it throwing?

– ManWithBear
Mar 24 at 11:06



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319354%2fswift-multi-selection-tableview-occurs-error-while-unselecting-rows%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?