- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含部分标题的 collectionView。在该部分的标题中,我添加了另一个 collectionView,它显示推荐的配置文件供用户关注,并且它水平滚动。
我无法从 ReuseableView(包含第二个 Collection View )推送 View Controller ,因此我创建了一个协议(protocol),该协议(protocol)将包含一个可以为我推送 View Controller 的函数。
当我点击个人资料(单元格)时,它会将我推送到我自己的个人资料。因为我抓不到indexPath.item
那是在另一个collectionView中。
协议(protocol)
HandleProfileTapped
的协议(protocol),名为 FeedReuseableView
的单元格是保存第二个 Collection View 的 sectionHeader 的名称。 protocol PeopleToFollowDelegate {
func handleProfileTapped(for cell: FeedReusableView)
}
// Create function to push users to the correct profile when selected
func handleProfileTapped(for header: FeedReusableView) {
print("profile tapped, push user to the correct profile page")
let header = FeedReusableView()
//try to grab the indexpath item so the corrext data is pushed
let user = header.peopleToFollow // ??? What goes here? I cannot grab index path
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let profileViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as? ProfileViewController
profileViewController?.user? = user
self.navigationController?.pushViewController(profileViewController!, animated: true)
}
peopleToFollow = [User]()
是用户将在部分标题中看到的推荐配置文件。 中频 Collection View 不在节标题中,然后我会像这样轻松获取 indexPath // When profile is tapped, push user to userProfile
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let user = peopleToFollow[indexPath.item]
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let profileViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as? ProfileViewController
profileViewController?.user = user
// Then push to next controller ( profile)
}
var delegate: PeopleToFollowDelegate?
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
// Return the number of profiles
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return peopleToFollow.count
}
//Display the recommended profiles
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "profilesCell", for: indexPath) as! PeopleToFollowCollectionCell
cell.user = peopleToFollow[indexPath.item]
return cell
}
// When profile is tapped, push user to userProfile
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
profilesTapped()
}
@objc func profilesTapped() {
delegate?.handleProfileTapped(for: self)
}
最佳答案
您可以从更改 didSelectRow 的实现
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
profilesTapped()
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
profilesTapped(user: peopleToFollow[indexPath.item])
}
@objc func profilesTapped(user: User) {
delegate?.handleProfileTapped(for: user)
}
func handleProfileTapped(for user: User) {
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
if let profileViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as? ProfileViewController {
profileViewController.user = user
self.navigationController?.pushViewController(profileViewController, animated: true)
}
关于ios - 如何从代表的 Collection View 单元格中获取 indexPath 项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58108705/
我正在尝试在我的 UITableView 上调用 reloadData。我在没有界面生成器的情况下制作我的应用程序。 此代码适用于 Interface Builder,但似乎没有。 当我将我的代码与我
有人可以解释 UIAlertView 的委托(delegate)是如何工作的吗?它是自动调用还是我必须调用它?例如: - (void)alertView:(UIAlertView *)alertVie
编辑:好吧,根据其他人的建议,我创建了一个最小的示例......并且它有效,因此我将在未来与任何人分享它。这是工作代码: #include #include using namespace std
unicode 是 ,它被用在 XML 文档中。 最佳答案 查看图表:unicodelookup.com 换行符。 关于html - unicode字符是什么 代表?,我们在Stack Overflo
我有一个应用程序,可以以编程方式在配置的 Facebook 页面上发帖。我的应用程序显然已批准管理页面和发布页面权限,并且我正在使用页面访问 token 从现在开始一切正常,但最近当我在页面提要上发布
代表 NCAA 男子篮球分组的最佳数据库模式是什么?如果您不熟悉,请点击以下链接:http://www.cbssports.com/collegebasketball/mayhem/brackets/
所以我一直在阅读这个关于如何使用 Frida 的教程:https://www.frida.re/docs/functions/我遇到过以下情况: $ ./client 127.0.0.1 connec
委托(delegate)函数返回之前是否需要调用replyHandler?我需要进行几次 Web 服务 API 调用才能回复,以下实现正确吗? func session(_ session: WCSe
下面提到的是我的 textField 委托(delegate)方法,我正在使用 IQKeyBoardSwift 作为智能键盘。我尝试移除我的键盘,但我仍然没有收到任何关于接受“开始触摸”的方法的调用
我有一个表格 View ,其中几乎没有用于数据输入的文本字段和弹出窗口。我想将其中一些表示为强制性的。我不知道如何讨厌星号。任何帮助将不胜感激。 最佳答案 我认为你可以使用自定义 UITableVie
例如,我知道如何使用 numpy 对数组进行切片 v[1, :, :] 现在我想要一个函数将切片 (1,1,None) 作为输入并返回 v[1,:,:] 问题是我不知道如何表示省略号 最佳答案 您可以
修订... 应用程序的关键是与数据库服务器通信。服务器对应用程序的响应都是 XML 格式的。有几个屏幕。例如,屏幕 1 列出了用户的信息,屏幕 2 列出了用户过去的交易,允许新交易,等等。 这是我的
我想知道映射/表示内存的最佳方式是什么。我的意思是,例如,如何描述一个结构及其所有字段都被序列化。 我正在创建一个 RPC 库,它将使用 dwarf 调试数据创建客户端和服务器,因此我需要创建一个函数
如果我有一个实现了两个协议(protocol)的 View Controller : @interface CustomerOperationsViewController : UIViewContr
在 Objective-C 中我可以做这样的事情: @property (nonatomic, weak) id someObject; 如何在swift中做到这一点?我试过这个: let someO
我成功地使用了相当棒的 connection:didReceiveAuthenticationChallenge: NSURLConnectionDelegate 委托(delegate)方法。很酷。
我正在寻找原始数据类型的 @NonNull 等效 Java 注释。我知道原始数据不能为 null,但我找不到替代方法。 我想要实现的在逻辑上等同于: int mPageNumber; public v
我正在学习 Git,如果我能描述代表 Git 存储库的数学结构,那就太好了。例如:它是一个有向无环图;它的节点代表提交;它的节点有代表分支等的标签(每个节点最多一个标签,没有标签使用两次)。(我知道这
我看过很多与委托(delegate)相关的帖子,我想知道引用它们的正确方法。假设我有一个声明如下的对象: @interface MyViewController : UITableViewContro
我有这个类: public class Order { int OrderId {get; set;} string CustomerName {get; set;} } 我也声明下面的变
我是一名优秀的程序员,十分优秀!