Swift sorting tableview into separate sections
I've written a program where a user can take pictures and track information about their miniature collections and everything works as intended. Now I'm looking to add some different functionality for the tableview, and I'm not quite sure what would be the best way to go about it. At present when the user adds a model, it appends to a single dictionary of dictionaries then displays it in the tableview in the order it was appended. I would like to sort or separate the data into separate sections based on what codex the model is from.
Whether it would be better to generate separate sections programmatically or use an index, I'm not sure. But in either case, I am at a complete loss of how to accomplish this.
Here is the tableview code I currently have, in case it helps
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return models.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Dequeue reusable Cell
let cell = tableView.dequeueReusableCell(withIdentifier: "modelCell", for: indexPath) as! modelCellTableViewCell
// Fetch Item
let model = models[indexPath.row]
// Configure Table View Cell
cell.modelNickname?.text = model.modelNickname
cell.modelNickname.textColor = UIColor(red:0.24, green:0.31, blue:0.35, alpha:1.0)
cell.modelName?.text = model.modelName
cell.codexName?.text = model.codexName
cell.modelOption1?.text = model.modelOption1
cell.modelOption2?.text = model.modelOption2
cell.modelOption3?.text = model.modelOption3
cell.modelOption4?.text = model.modelOption4
let fileManager = FileManager.default
let imageName = model.codexName + model.modelName + model.modelOption1
let imagePath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(imageName)
if fileManager.fileExists(atPath: imagePath){
cell.modelImage.image = UIImage(contentsOfFile: imagePath)
}else{
print("No Image found")
}
return cell
}
Any help/suggestions you could offer would be a big help.
ios swift uitableview sections
add a comment |
I've written a program where a user can take pictures and track information about their miniature collections and everything works as intended. Now I'm looking to add some different functionality for the tableview, and I'm not quite sure what would be the best way to go about it. At present when the user adds a model, it appends to a single dictionary of dictionaries then displays it in the tableview in the order it was appended. I would like to sort or separate the data into separate sections based on what codex the model is from.
Whether it would be better to generate separate sections programmatically or use an index, I'm not sure. But in either case, I am at a complete loss of how to accomplish this.
Here is the tableview code I currently have, in case it helps
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return models.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Dequeue reusable Cell
let cell = tableView.dequeueReusableCell(withIdentifier: "modelCell", for: indexPath) as! modelCellTableViewCell
// Fetch Item
let model = models[indexPath.row]
// Configure Table View Cell
cell.modelNickname?.text = model.modelNickname
cell.modelNickname.textColor = UIColor(red:0.24, green:0.31, blue:0.35, alpha:1.0)
cell.modelName?.text = model.modelName
cell.codexName?.text = model.codexName
cell.modelOption1?.text = model.modelOption1
cell.modelOption2?.text = model.modelOption2
cell.modelOption3?.text = model.modelOption3
cell.modelOption4?.text = model.modelOption4
let fileManager = FileManager.default
let imageName = model.codexName + model.modelName + model.modelOption1
let imagePath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(imageName)
if fileManager.fileExists(atPath: imagePath){
cell.modelImage.image = UIImage(contentsOfFile: imagePath)
}else{
print("No Image found")
}
return cell
}
Any help/suggestions you could offer would be a big help.
ios swift uitableview sections
This should help. stackoverflow.com/a/51846331/7734643
– Rakesha Shastri
Nov 21 '18 at 12:54
@RakeshaShastri the idea of using a second class is an interesting one that I will have to play with. Unfortunately the code you provided in your link doesn't seem to be working for me. Thank you all the same
– Eric McCracken
Nov 22 '18 at 0:51
What issues are you facing?
– Rakesha Shastri
Nov 22 '18 at 4:14
@RakeshaShastri I am trying to figure out what to place into cellForRowAt so that everything works. At present Im getting an Index out of range alarm
– Eric McCracken
Nov 22 '18 at 21:25
add a comment |
I've written a program where a user can take pictures and track information about their miniature collections and everything works as intended. Now I'm looking to add some different functionality for the tableview, and I'm not quite sure what would be the best way to go about it. At present when the user adds a model, it appends to a single dictionary of dictionaries then displays it in the tableview in the order it was appended. I would like to sort or separate the data into separate sections based on what codex the model is from.
Whether it would be better to generate separate sections programmatically or use an index, I'm not sure. But in either case, I am at a complete loss of how to accomplish this.
Here is the tableview code I currently have, in case it helps
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return models.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Dequeue reusable Cell
let cell = tableView.dequeueReusableCell(withIdentifier: "modelCell", for: indexPath) as! modelCellTableViewCell
// Fetch Item
let model = models[indexPath.row]
// Configure Table View Cell
cell.modelNickname?.text = model.modelNickname
cell.modelNickname.textColor = UIColor(red:0.24, green:0.31, blue:0.35, alpha:1.0)
cell.modelName?.text = model.modelName
cell.codexName?.text = model.codexName
cell.modelOption1?.text = model.modelOption1
cell.modelOption2?.text = model.modelOption2
cell.modelOption3?.text = model.modelOption3
cell.modelOption4?.text = model.modelOption4
let fileManager = FileManager.default
let imageName = model.codexName + model.modelName + model.modelOption1
let imagePath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(imageName)
if fileManager.fileExists(atPath: imagePath){
cell.modelImage.image = UIImage(contentsOfFile: imagePath)
}else{
print("No Image found")
}
return cell
}
Any help/suggestions you could offer would be a big help.
ios swift uitableview sections
I've written a program where a user can take pictures and track information about their miniature collections and everything works as intended. Now I'm looking to add some different functionality for the tableview, and I'm not quite sure what would be the best way to go about it. At present when the user adds a model, it appends to a single dictionary of dictionaries then displays it in the tableview in the order it was appended. I would like to sort or separate the data into separate sections based on what codex the model is from.
Whether it would be better to generate separate sections programmatically or use an index, I'm not sure. But in either case, I am at a complete loss of how to accomplish this.
Here is the tableview code I currently have, in case it helps
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return models.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Dequeue reusable Cell
let cell = tableView.dequeueReusableCell(withIdentifier: "modelCell", for: indexPath) as! modelCellTableViewCell
// Fetch Item
let model = models[indexPath.row]
// Configure Table View Cell
cell.modelNickname?.text = model.modelNickname
cell.modelNickname.textColor = UIColor(red:0.24, green:0.31, blue:0.35, alpha:1.0)
cell.modelName?.text = model.modelName
cell.codexName?.text = model.codexName
cell.modelOption1?.text = model.modelOption1
cell.modelOption2?.text = model.modelOption2
cell.modelOption3?.text = model.modelOption3
cell.modelOption4?.text = model.modelOption4
let fileManager = FileManager.default
let imageName = model.codexName + model.modelName + model.modelOption1
let imagePath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(imageName)
if fileManager.fileExists(atPath: imagePath){
cell.modelImage.image = UIImage(contentsOfFile: imagePath)
}else{
print("No Image found")
}
return cell
}
Any help/suggestions you could offer would be a big help.
ios swift uitableview sections
ios swift uitableview sections
edited Nov 21 '18 at 16:09
asked Nov 21 '18 at 12:49
Eric McCracken
184
184
This should help. stackoverflow.com/a/51846331/7734643
– Rakesha Shastri
Nov 21 '18 at 12:54
@RakeshaShastri the idea of using a second class is an interesting one that I will have to play with. Unfortunately the code you provided in your link doesn't seem to be working for me. Thank you all the same
– Eric McCracken
Nov 22 '18 at 0:51
What issues are you facing?
– Rakesha Shastri
Nov 22 '18 at 4:14
@RakeshaShastri I am trying to figure out what to place into cellForRowAt so that everything works. At present Im getting an Index out of range alarm
– Eric McCracken
Nov 22 '18 at 21:25
add a comment |
This should help. stackoverflow.com/a/51846331/7734643
– Rakesha Shastri
Nov 21 '18 at 12:54
@RakeshaShastri the idea of using a second class is an interesting one that I will have to play with. Unfortunately the code you provided in your link doesn't seem to be working for me. Thank you all the same
– Eric McCracken
Nov 22 '18 at 0:51
What issues are you facing?
– Rakesha Shastri
Nov 22 '18 at 4:14
@RakeshaShastri I am trying to figure out what to place into cellForRowAt so that everything works. At present Im getting an Index out of range alarm
– Eric McCracken
Nov 22 '18 at 21:25
This should help. stackoverflow.com/a/51846331/7734643
– Rakesha Shastri
Nov 21 '18 at 12:54
This should help. stackoverflow.com/a/51846331/7734643
– Rakesha Shastri
Nov 21 '18 at 12:54
@RakeshaShastri the idea of using a second class is an interesting one that I will have to play with. Unfortunately the code you provided in your link doesn't seem to be working for me. Thank you all the same
– Eric McCracken
Nov 22 '18 at 0:51
@RakeshaShastri the idea of using a second class is an interesting one that I will have to play with. Unfortunately the code you provided in your link doesn't seem to be working for me. Thank you all the same
– Eric McCracken
Nov 22 '18 at 0:51
What issues are you facing?
– Rakesha Shastri
Nov 22 '18 at 4:14
What issues are you facing?
– Rakesha Shastri
Nov 22 '18 at 4:14
@RakeshaShastri I am trying to figure out what to place into cellForRowAt so that everything works. At present Im getting an Index out of range alarm
– Eric McCracken
Nov 22 '18 at 21:25
@RakeshaShastri I am trying to figure out what to place into cellForRowAt so that everything works. At present Im getting an Index out of range alarm
– Eric McCracken
Nov 22 '18 at 21:25
add a comment |
0
active
oldest
votes
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412416%2fswift-sorting-tableview-into-separate-sections%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412416%2fswift-sorting-tableview-into-separate-sections%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
This should help. stackoverflow.com/a/51846331/7734643
– Rakesha Shastri
Nov 21 '18 at 12:54
@RakeshaShastri the idea of using a second class is an interesting one that I will have to play with. Unfortunately the code you provided in your link doesn't seem to be working for me. Thank you all the same
– Eric McCracken
Nov 22 '18 at 0:51
What issues are you facing?
– Rakesha Shastri
Nov 22 '18 at 4:14
@RakeshaShastri I am trying to figure out what to place into cellForRowAt so that everything works. At present Im getting an Index out of range alarm
– Eric McCracken
Nov 22 '18 at 21:25