【问题标题】:Accessing index of array of buttons then pushing to different VC with info访问按钮数组的索引,然后使用信息推送到不同的 VC
【发布时间】:2016-01-05 01:06:20
【问题描述】:

在用于创建事件的应用程序中,每个集合视图单元格都有一组按钮,其背景显示参加所述事件的用户的个人资料图片(索引路径处的对象)。这一切都很好,它们显示正确,但我想这样做,以便当用户选择某个按钮时,它会与照片所属的用户一起推送到配置文件视图控制器。

这是我到目前为止的代码......

在主 VC 的 cellForRowAtIndexPath 方法中......就像我说的那样,它显示完美。

            //gets profile pictures for image view array on back of cell

            if let attendeeRelation : PFRelation = event?.relationForKey("eventAttendees") {

                attendeeRelation.query()?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

                    if ((objects) != nil) {

                        self.tempArray = objects as? [PFUser]

                        for var index = 0; index < objects!.count; ++index {

                            let buttonView = cell.buttonsArray[index]

                            let usr : PFUser = (self.tempArray?[index] as PFUser?)!

                            usr.fetchIfNeededInBackgroundWithBlock({ (object, error) -> Void in

                                if let picture = object!.objectForKey("profilePicture") as? PFFile {
                                    picture.getDataInBackgroundWithBlock({ (data, error) -> Void in                      
                                        buttonView.setBackgroundImage(UIImage(data: data!), forState: UIControlState.Normal)
                                    })
                                }
                            })
                        }
                    }

                    else {

                        print(error)
                    }

                })

            }

为 segue 方法做准备,我遇到了麻烦...

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if (segue.identifier == "pushToProfile") {

        //get index of button here then push to profile VC with correct user

        let profileVC = segue.destinationViewController as! ProfileViewController
    }
}

我应该只是子类化按钮并给它一个用户属性然后从那里开始吗?我觉得这可能是最简单的方法。还有人有建议吗?谢谢你,像往常一样非常感激。

【问题讨论】:

    标签: ios arrays parse-platform indexing swift2


    【解决方案1】:

    我做到了!

    子类化按钮并为其赋予“用户”属性就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-01
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2018-09-29
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多