索引1在Swift中使用时,如何终止/关闭索引0内的所有操作?

时间:2015-04-20 13:56:09

标签: ios iphone swift ios8 xcode6

我正在尝试使用几个标签制作一堆过滤器选项,而且我在iOS开发中也是新手,我遇到的问题似乎发生在像我这样的初学者身上。这是我的问题:"如果索引== 1点击并且新操作进入索引== 1"如何终止index == 0内的所有操作。我已经推出了" .reloaddata()"每个指数,但似乎不起作用。这是我正在处理的代码:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if ((indexPath.row)==0){
            println("index number 0 Clicked")
            self.generateThumbnail()

            //Setting up GPU Context
            var options = [kCIContextWorkingColorSpace: NSNull()]
            var myEAGLContext = EAGLContext(API: EAGLRenderingAPI.OpenGLES2)
            self.context = CIContext(EAGLContext: myEAGLContext, options: options)
            //Here below try to move to did select
            var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
            //Did this in CoreDataSeeder.swift
            self.managedObjectContext = appDelegate.managedObjectContext


            //Seeding Core Data
            var seeder = CoreDataSeeder(context: appDelegate.managedObjectContext!)

            let fetchRequest = NSFetchRequest(entityName: "Filter")
            var error: NSError?
            if let filters = self.managedObjectContext.executeFetchRequest(fetchRequest, error: &error) as? [Filter] {
                if filters.isEmpty {
                    seeder.seedCoreDataTwo()
                    self.filters = self.managedObjectContext.executeFetchRequest(fetchRequest, error: &error) as! [Filter]
                } else {
                    self.filters = filters
                }
            }

            println("Number of filters view did load: \(filters.count)")
            println("Number of filters view did load: \(SecondFilters.count)")
            self.resetFilterThumbnails()
            self.resetSecondFilterThumbnails()
            self.collectionView.delegate = self
            self.collectionView.dataSource = self
        }
if ((indexPath.row)==1){
            println("index number 1 Clicked")
            /*self.collectionView.removeFromSuperview()*/ // This code is awesome and it works
            self.generateThumbnail()

            //Setting up GPU Context
            var options = [kCIContextWorkingColorSpace: NSNull()]
            var myEAGLContext = EAGLContext(API: EAGLRenderingAPI.OpenGLES2)
            self.context = CIContext(EAGLContext: myEAGLContext, options: options)
            //Here below try to move to did select
            var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
            //Did this in CoreDataSeeder.swift
            self.managedObjectContext = appDelegate.managedObjectContext


            //Seeding Core Data
            var seeder = CoreDataSeeder(context: appDelegate.managedObjectContext!)

            let fetchRequest = NSFetchRequest(entityName: "Filter")
            var error: NSError?
            if let filters = self.managedObjectContext.executeFetchRequest(fetchRequest, error: &error) as? [Filter] {
                if filters.isEmpty {
                    seeder.seedCoreData()
                    self.filters = self.managedObjectContext.executeFetchRequest(fetchRequest, error: &error) as! [Filter]
                } else {
                    self.filters = filters
                }
            }

            println("Number of filters view did load: \(filters.count)")
            println("Number of filters view did load: \(SecondFilters.count)")
            self.resetFilterThumbnails()
            self.resetSecondFilterThumbnails()
            self.collectionView.delegate = self
            self.collectionView.dataSource = self

        }
}

如果你能帮助我,我将不胜感激,谢谢你

1 个答案:

答案 0 :(得分:0)

好的,您的评论有助于澄清您的目标。

UITableViewDelegate协议定义了一个方法tableView:willSelectRowAtIndexPath:

如果您实施该方法,您有机会控制当用户点击表格视图中的单元格时会发生什么。如果您返回nil,则不会选择该单元格。

因此,当用户点击其他一个单元格时,添加设置实例变量的逻辑。

然后在您的tableView:willSelectRowAtIndexPath:方法中,检查该实例变量。如果您确定用户正在尝试选择顶部单元格而您不想要它们,则让该方法返回nil。