nested sections in the tableview in swift
up vote
0
down vote
favorite
{
"data":[
{
"mainquestion":"was the staff",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}, {
"mainquestion":"Please tell the feedback",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}
]
}
This is my json data.I need to display the data in the tableview as below screen shot.
This is the screen shot.I need to display in this way.
Currently my code is below.
func numberOfSections(in tableView: UITableView) -> Int {
return dummyDataViewModel.numberOfSections()
print(dummyDataViewModel.numberOfSections())
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let identifier = "DummyDataHeaderCell"
var headercell: EQ_DummyDataHeader! = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
if headercell == nil {
tableView.register(UINib(nibName: "EQ_DummyDataHeader", bundle: nil), forCellReuseIdentifier: identifier)
headercell = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
}
headercell.setReviewData(reviews:self.dummyDataViewModel.titleForHeaderInSection(atsection:section))
return headercell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if tableView == tableview{
return 50
}
return 20
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dummyDataViewModel.numberOfRowsIn(section: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = dummyDataViewModel.titleForHeaderInSection(atsection: indexPath.section)
print(model.answerType1)
print(model.answerType1?.rawValue)
let c = model.answerType1
let cellClass = c?.cellType().getClass()
print(cellClass)
let cell = tableView.dequeueReusableCell(withIdentifier: (cellClass?.cellReuseIdentifier())!, for: indexPath) as! BaseCell
print(cell)
cell.selectionStyle = .none
let optionModel = dummyDataViewModel.datafordisplay(atindex: indexPath)
cell.setOptions(Options1: optionModel)
cell.type = c?.cellType()
cell.delegate = self
cell.textdelegate = self
cell.textdelegate1 = self
cell.datedelegateDatepicker1 = self
cell.selectDateDelegate = self
if optionModel.isSelected! {
cell.setOptions1(OptionsSelected:optionModel)
cell.TextDisplay(options:optionModel)
} else {
cell.setOptions1(OptionsisSelected:optionModel)
cell.setOptions(OptionsisSelected:optionModel)
cell.setOptions1(OptionsisSelected:optionModel)
cell.TextNotDisplay(options:optionModel)
}
print(cell.type)
if cell.type == .starratingtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
else if cell.type == .checkboxtype{
cell.selectionStyle = .none
}
else if cell.type == .radiotype{
cell.selectionStyle = .none
}
else if cell.type == .textfieldtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
return cell
}
In the view model:-
func numberOfSections() -> Int{
print((datasourceModel.dataListArray?.count)!)
return (datasourceModel.dataListArray?.count)!
}
func titleForHeaderInSection(atsection section: Int) -> EQ_DummyDataModel {
print(datasourceModel.dataListArray![section])
return datasourceModel.dataListArray![section]
}
func numberOfRowsIn(section:Int) -> Int {
print( datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0)
return datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0
}
func datafordisplay(atindex indexPath: IndexPath) -> EQ_OptionModel{
print(datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row])
return datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row]
}
I am doing in mvvm .So how to implement the nested section in this code?
What are the changes needed to do in the number of sections and datasource.
ios json swift mvvm uitableviewsectionheader
add a comment |
up vote
0
down vote
favorite
{
"data":[
{
"mainquestion":"was the staff",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}, {
"mainquestion":"Please tell the feedback",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}
]
}
This is my json data.I need to display the data in the tableview as below screen shot.
This is the screen shot.I need to display in this way.
Currently my code is below.
func numberOfSections(in tableView: UITableView) -> Int {
return dummyDataViewModel.numberOfSections()
print(dummyDataViewModel.numberOfSections())
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let identifier = "DummyDataHeaderCell"
var headercell: EQ_DummyDataHeader! = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
if headercell == nil {
tableView.register(UINib(nibName: "EQ_DummyDataHeader", bundle: nil), forCellReuseIdentifier: identifier)
headercell = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
}
headercell.setReviewData(reviews:self.dummyDataViewModel.titleForHeaderInSection(atsection:section))
return headercell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if tableView == tableview{
return 50
}
return 20
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dummyDataViewModel.numberOfRowsIn(section: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = dummyDataViewModel.titleForHeaderInSection(atsection: indexPath.section)
print(model.answerType1)
print(model.answerType1?.rawValue)
let c = model.answerType1
let cellClass = c?.cellType().getClass()
print(cellClass)
let cell = tableView.dequeueReusableCell(withIdentifier: (cellClass?.cellReuseIdentifier())!, for: indexPath) as! BaseCell
print(cell)
cell.selectionStyle = .none
let optionModel = dummyDataViewModel.datafordisplay(atindex: indexPath)
cell.setOptions(Options1: optionModel)
cell.type = c?.cellType()
cell.delegate = self
cell.textdelegate = self
cell.textdelegate1 = self
cell.datedelegateDatepicker1 = self
cell.selectDateDelegate = self
if optionModel.isSelected! {
cell.setOptions1(OptionsSelected:optionModel)
cell.TextDisplay(options:optionModel)
} else {
cell.setOptions1(OptionsisSelected:optionModel)
cell.setOptions(OptionsisSelected:optionModel)
cell.setOptions1(OptionsisSelected:optionModel)
cell.TextNotDisplay(options:optionModel)
}
print(cell.type)
if cell.type == .starratingtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
else if cell.type == .checkboxtype{
cell.selectionStyle = .none
}
else if cell.type == .radiotype{
cell.selectionStyle = .none
}
else if cell.type == .textfieldtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
return cell
}
In the view model:-
func numberOfSections() -> Int{
print((datasourceModel.dataListArray?.count)!)
return (datasourceModel.dataListArray?.count)!
}
func titleForHeaderInSection(atsection section: Int) -> EQ_DummyDataModel {
print(datasourceModel.dataListArray![section])
return datasourceModel.dataListArray![section]
}
func numberOfRowsIn(section:Int) -> Int {
print( datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0)
return datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0
}
func datafordisplay(atindex indexPath: IndexPath) -> EQ_OptionModel{
print(datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row])
return datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row]
}
I am doing in mvvm .So how to implement the nested section in this code?
What are the changes needed to do in the number of sections and datasource.
ios json swift mvvm uitableviewsectionheader
how to implement it?
– clydececiljohn
Nov 22 at 10:02
How to implement the nested sections in the tableview?
– clydececiljohn
Nov 22 at 10:45
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
{
"data":[
{
"mainquestion":"was the staff",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}, {
"mainquestion":"Please tell the feedback",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}
]
}
This is my json data.I need to display the data in the tableview as below screen shot.
This is the screen shot.I need to display in this way.
Currently my code is below.
func numberOfSections(in tableView: UITableView) -> Int {
return dummyDataViewModel.numberOfSections()
print(dummyDataViewModel.numberOfSections())
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let identifier = "DummyDataHeaderCell"
var headercell: EQ_DummyDataHeader! = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
if headercell == nil {
tableView.register(UINib(nibName: "EQ_DummyDataHeader", bundle: nil), forCellReuseIdentifier: identifier)
headercell = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
}
headercell.setReviewData(reviews:self.dummyDataViewModel.titleForHeaderInSection(atsection:section))
return headercell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if tableView == tableview{
return 50
}
return 20
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dummyDataViewModel.numberOfRowsIn(section: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = dummyDataViewModel.titleForHeaderInSection(atsection: indexPath.section)
print(model.answerType1)
print(model.answerType1?.rawValue)
let c = model.answerType1
let cellClass = c?.cellType().getClass()
print(cellClass)
let cell = tableView.dequeueReusableCell(withIdentifier: (cellClass?.cellReuseIdentifier())!, for: indexPath) as! BaseCell
print(cell)
cell.selectionStyle = .none
let optionModel = dummyDataViewModel.datafordisplay(atindex: indexPath)
cell.setOptions(Options1: optionModel)
cell.type = c?.cellType()
cell.delegate = self
cell.textdelegate = self
cell.textdelegate1 = self
cell.datedelegateDatepicker1 = self
cell.selectDateDelegate = self
if optionModel.isSelected! {
cell.setOptions1(OptionsSelected:optionModel)
cell.TextDisplay(options:optionModel)
} else {
cell.setOptions1(OptionsisSelected:optionModel)
cell.setOptions(OptionsisSelected:optionModel)
cell.setOptions1(OptionsisSelected:optionModel)
cell.TextNotDisplay(options:optionModel)
}
print(cell.type)
if cell.type == .starratingtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
else if cell.type == .checkboxtype{
cell.selectionStyle = .none
}
else if cell.type == .radiotype{
cell.selectionStyle = .none
}
else if cell.type == .textfieldtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
return cell
}
In the view model:-
func numberOfSections() -> Int{
print((datasourceModel.dataListArray?.count)!)
return (datasourceModel.dataListArray?.count)!
}
func titleForHeaderInSection(atsection section: Int) -> EQ_DummyDataModel {
print(datasourceModel.dataListArray![section])
return datasourceModel.dataListArray![section]
}
func numberOfRowsIn(section:Int) -> Int {
print( datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0)
return datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0
}
func datafordisplay(atindex indexPath: IndexPath) -> EQ_OptionModel{
print(datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row])
return datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row]
}
I am doing in mvvm .So how to implement the nested section in this code?
What are the changes needed to do in the number of sections and datasource.
ios json swift mvvm uitableviewsectionheader
{
"data":[
{
"mainquestion":"was the staff",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}, {
"mainquestion":"Please tell the feedback",
"items":[
{
"button_type":"2",
"question": "Gender",
"options": ["Male","Female"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
},
{
"button_type":"2",
"question": "How old are you",
"options": ["Under 18","Age 18 to 35","Age 36 to 50","Age 51 to 70","70 and above"]
}
]
}
]
}
This is my json data.I need to display the data in the tableview as below screen shot.
This is the screen shot.I need to display in this way.
Currently my code is below.
func numberOfSections(in tableView: UITableView) -> Int {
return dummyDataViewModel.numberOfSections()
print(dummyDataViewModel.numberOfSections())
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let identifier = "DummyDataHeaderCell"
var headercell: EQ_DummyDataHeader! = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
if headercell == nil {
tableView.register(UINib(nibName: "EQ_DummyDataHeader", bundle: nil), forCellReuseIdentifier: identifier)
headercell = tableView.dequeueReusableCell(withIdentifier: identifier) as? EQ_DummyDataHeader
}
headercell.setReviewData(reviews:self.dummyDataViewModel.titleForHeaderInSection(atsection:section))
return headercell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if tableView == tableview{
return 50
}
return 20
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dummyDataViewModel.numberOfRowsIn(section: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = dummyDataViewModel.titleForHeaderInSection(atsection: indexPath.section)
print(model.answerType1)
print(model.answerType1?.rawValue)
let c = model.answerType1
let cellClass = c?.cellType().getClass()
print(cellClass)
let cell = tableView.dequeueReusableCell(withIdentifier: (cellClass?.cellReuseIdentifier())!, for: indexPath) as! BaseCell
print(cell)
cell.selectionStyle = .none
let optionModel = dummyDataViewModel.datafordisplay(atindex: indexPath)
cell.setOptions(Options1: optionModel)
cell.type = c?.cellType()
cell.delegate = self
cell.textdelegate = self
cell.textdelegate1 = self
cell.datedelegateDatepicker1 = self
cell.selectDateDelegate = self
if optionModel.isSelected! {
cell.setOptions1(OptionsSelected:optionModel)
cell.TextDisplay(options:optionModel)
} else {
cell.setOptions1(OptionsisSelected:optionModel)
cell.setOptions(OptionsisSelected:optionModel)
cell.setOptions1(OptionsisSelected:optionModel)
cell.TextNotDisplay(options:optionModel)
}
print(cell.type)
if cell.type == .starratingtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
else if cell.type == .checkboxtype{
cell.selectionStyle = .none
}
else if cell.type == .radiotype{
cell.selectionStyle = .none
}
else if cell.type == .textfieldtype{
cell.selectionStyle = .none
}
else if cell.type == .smileytype{
cell.selectionStyle = .none
}
return cell
}
In the view model:-
func numberOfSections() -> Int{
print((datasourceModel.dataListArray?.count)!)
return (datasourceModel.dataListArray?.count)!
}
func titleForHeaderInSection(atsection section: Int) -> EQ_DummyDataModel {
print(datasourceModel.dataListArray![section])
return datasourceModel.dataListArray![section]
}
func numberOfRowsIn(section:Int) -> Int {
print( datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0)
return datasourceModel.dataListArray?[section].optionsModelArray.count ?? 0
}
func datafordisplay(atindex indexPath: IndexPath) -> EQ_OptionModel{
print(datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row])
return datasourceModel.dataListArray![indexPath.section].optionsModelArray[indexPath.row]
}
I am doing in mvvm .So how to implement the nested section in this code?
What are the changes needed to do in the number of sections and datasource.
ios json swift mvvm uitableviewsectionheader
ios json swift mvvm uitableviewsectionheader
edited Nov 22 at 9:27
Pankaj
312513
312513
asked Nov 22 at 8:34
clydececiljohn
55
55
how to implement it?
– clydececiljohn
Nov 22 at 10:02
How to implement the nested sections in the tableview?
– clydececiljohn
Nov 22 at 10:45
add a comment |
how to implement it?
– clydececiljohn
Nov 22 at 10:02
How to implement the nested sections in the tableview?
– clydececiljohn
Nov 22 at 10:45
how to implement it?
– clydececiljohn
Nov 22 at 10:02
how to implement it?
– clydececiljohn
Nov 22 at 10:02
How to implement the nested sections in the tableview?
– clydececiljohn
Nov 22 at 10:45
How to implement the nested sections in the tableview?
– clydececiljohn
Nov 22 at 10:45
add a comment |
active
oldest
votes
active
oldest
votes
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%2f53426776%2fnested-sections-in-the-tableview-in-swift%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
how to implement it?
– clydececiljohn
Nov 22 at 10:02
How to implement the nested sections in the tableview?
– clydececiljohn
Nov 22 at 10:45