[英]add Single Value inside an existing Section in UITableView
i have a tableview with sections for adding section i created an struct
: 我有一个带有添加部分的部分的tableview我创建了一个
struct
:
struct datesStruct {
var sectionYear : String!
var sectionMonth : [String]!
}
var datesStructArray = [datesStruct]()
now i want to add a single value inside my exiting sections after checking if the section is satisfying my condition, any idea how am gonna do that ??? 现在我想在检查该节是否满足我的条件后在我的退出节中添加一个值,不知道该怎么做?
eg : 例如:
if myTableViewSection1 == 2016{
//add value into this section
}
searched a lot about this but didn't get anything yet , if anybody knows then please do help me thanks 搜索了很多关于此,但还没有得到任何东西,如果有人知道,那么请帮我谢谢
First, put this function outside of your class (before "class" or after the last "}": 首先,将此函数放在类之外(在“类”之前或最后一个“}”之后:
func == (leftItem: DatesStruct, rightItem: DatesStruct) -> Bool{
return leftItem.sectionYear == rightItem.sectionYear
}
Then Use this: 然后使用:
struct DatesStruct: Equatable{
var sectionYear : String!
var sectionMonth : [String]!
}
var datesStructArray = [DatesStruct]()
func addMonthToYear(year: String, month: String){
if let foundItem: DatesStruct = datesStructArray.filter({$0.sectionYear == year}).first {
datesStructArray[datesStructArray.indexOf(foundItem)!].sectionMonth.append(month)
}
}
Simply pass the year you're looking for and the month you want to add to addMonthToYear 只需将要查找的年份和要添加的月份传递给addMonthToYear
Declare an initializer 声明一个初始化器
struct datesStruct {
var sectionYear : String!
var sectionMonth : [String]!
init(sectionYear: String!, sectionMonth: [String]!) {
self.sectionYear = sectionYear
self.sectionMonth = sectionMonth
}
}
var datesStructArray = [datesStruct(sectionYear: "year", sectionMonth: ["month1", "month2"])]
Then check whether the sectionMonth
contains desired string 然后检查
sectionMonth
是否包含所需的字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.