Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 分组排序数据_Ios_Swift_Xcode_Core Data - Fatal编程技术网

Ios 分组排序数据

Ios 分组排序数据,ios,swift,xcode,core-data,Ios,Swift,Xcode,Core Data,下面是我的界面的外观,如果我创建一个事件,它是黑色的,一旦我从action controller中选择yes或no,它就会相应地变为绿色或红色 如果我在行中选择一个事件并选择yes,它将变为绿色,我喜欢在yes部分下对其排序,如果no部分它将变为红色,我喜欢在no部分下对其排序。但是我不能这样做,因为我创建的所有事件都被分组在事件部分下。我想知道如何在它们所属的部分下发送事件 例如,我喜欢按组对事件进行排序,我喜欢在Yes下查看English101,在No和Geo 101下查看Math101,S

下面是我的界面的外观,如果我创建一个事件,它是黑色的,一旦我从action controller中选择yes或no,它就会相应地变为绿色或红色

如果我在行中选择一个事件并选择
yes
,它将变为
绿色
,我喜欢在
yes部分
下对其排序,如果
no部分
它将变为
红色
,我喜欢在
no部分
下对其排序。但是我不能这样做,因为我创建的所有事件都被分组在
事件部分
下。我想知道如何在它们所属的部分下发送事件

例如,我喜欢按组对事件进行排序,我喜欢在
Yes
下查看
English101
,在
No
Geo 101下查看
Math101
,Stats 101
停留在
Events
下。我花了很多时间在下面代码的不同地方填充
OncYes
OncNo
,但都没有成功

var eventTitleoc:[字符串]=[]
var oncYes:[字符串]=[]
变量oncNo:[字符串]=[]
var oncEventsPresent:[字符串]=[]
变量事件类型:[Int]=[]
变量oncEvents:[字符串]=[]
var eventScheduleOnc=[eventScheduleOnc]()
让sectionTitles:[字符串]=[“事件”、“是”、“否”]
重写func viewDidLoad(){
super.viewDidLoad()
eventDataOnc()
对于步幅中的i(从:0到:eventTitleOnc.count,由:1){
oncEventsPresent.append(eventTitleOnc[i])
}
myEventTableView.reloadData()
}
//节中的行数
public func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int
{
var typeOfEvent=0
如果(节==0)
{
typeOfEvent=oncEventsPresent.count
}
如果(节==1)
{
typeOfEvent=oncYes.count
}
如果(节==2)
{
typeOfEvent=oncNo.count
}
返回事件类型
}
//行单元格
public func tableView(tableView:UITableView,cellForRowAt indexPath:indexPath)->UITableViewCell{
让myEventCell=tableView.dequeueReusableCell(标识符为:“myCell”,代表:indexath)作为!EventTableViewCell
myEventCell.eventLabel.text=self.eventScheduleOnc[indexath.row].eventNameOnc
让eventDesc=self.eventScheduleOnc[indexPath.row].eventDecOnc
让eventStatus=eventDesc?.eventStatus
如果eventStatus==1{
myEventCell.eventLabel.textColor=UIColor.green
}
如果eventStatus==2,则为else{
myEventCell.eventLabel.textColor=UIColor.red
}
其他的
{
myEventCell.eventLabel.textColor=UIColor.black
}
}
返回myEventCell
}
//是否在索引路径中选择了行
func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath){
让eventDesc=NSEntityDescription.insertNewObject(forEntityName:“EventDec”,into:context)作为!EventDec
var eventSchOnc:EventScheduleOnc?
做{
让fetchRequestOnc:NSFetchRequest=EventScheduleOnc.fetchRequest()
fetchRequestOnc.returnsObjectsAsFaults=false
fetchRequestOnc.predicate=NSPredicate(格式:“eventNameOnc==%@”,self.oncEventsPresent[indexPath.row]作为字符串)
var eventschonobjects=[EventScheduleOnc]()
try eventschonobjects=context.fetch(fetchRequestOnc)
eventSchOnc=eventschonobjects[0]作为EventScheduleOnc
}
捕获{}
eventDesc.setValue(eventSchOnc,forKey:“eventScheduleOnc”)
let alert=UIAlertController(标题:“标题”,消息:“消息”,首选样式:。警报)
DispatchQueue.main.async{
addAction(UIAlertAction(标题:“是”,样式:。默认值){
eventDesc.setValue(1,forKey:“eventStatus”)
做{
尝试context.save()
self.myeventableview.reloadData()文件
}
捕获{}
})
addAction(UIAlertAction(标题:“否”,样式:。默认值){
eventDesc.setValue(2,forKey:“eventStatus”)
做{
尝试context.save()
self.myeventableview.reloadData()文件
}
捕获{}
})
}
当前(警报、动画:真、完成:无)
}
//标记:-核心数据
私有func eventDataOnc(){
让eventsOncFetchRequest=NSFetchRequest(entityName:“EventScheduleOnc”)
让primarySortDescriptor=NSSortDescriptor(键:“eventDecOnc.eventStatus”,升序:false)
让secondarySortDescriptor=NSSortDescriptor(键:“eventNameOnc”,升序:true)
EventsOnCetchRequest.sortDescriptors=[primarySortDescriptor,secondarySortDescriptor]
做
{
let results=try context.fetch(eventsOncFetchRequest)
如果results.count>0
{
为了得到结果
{
如果让eventDisTextOnc=(结果为AnyObject).value(forKey:“eventNameOnc”)作为?字符串
{
eventTitleOnc.append(eventDistextConc)
}
}
}
self.eventScheduleOnc=try context.fetch(eventsOncFetchRequest)as![eventScheduleOnc]
}
catch{print(error.localizedDescription)}
}

如何按组对这些数据进行排序?

我将使用包含3个部分的tableview:

enum Section { 
     case undecided, yes, no 
     static let all: [Section] = [.undecided, .yes, .no]
}
然后,我会将数据粘贴到数组字典中(或者是带有关联值的枚举数组):

您的数据源方法如下所示:

    extension V: UITableViewDataSource {
        func numberOfSections(in tableView: UITableView) -> Int {
            return Sections.all.count
        }
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return events[Sections.all[section]]!.count
        }
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: MyCell.self), for: indexPath) as MyCell
            cell.event = events[Sections.all[section]]!
            return cell
        }
    }

你的问题我搞不懂,我也不想费力地从你的鳕鱼身上找出你在说什么。@Duncac,如果这是明确的,请告诉我。什么是活动?显示定义。你们的活动是如何组织的?解释数据结构的布局以及所有内容的含义。
var events[Section: [String]] = [.undecided: [], .yes: [], .no: []]
    extension V: UITableViewDataSource {
        func numberOfSections(in tableView: UITableView) -> Int {
            return Sections.all.count
        }
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return events[Sections.all[section]]!.count
        }
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: MyCell.self), for: indexPath) as MyCell
            cell.event = events[Sections.all[section]]!
            return cell
        }
    }