首页 \ 问答 \ 如何在IOS中从UICollectionViewCell初始化弹出窗口视图(How to initialize popover view from UICollectionViewCell in IOS)

如何在IOS中从UICollectionViewCell初始化弹出窗口视图(How to initialize popover view from UICollectionViewCell in IOS)

我一直在跟踪使用故事板的iPad应用程序,我已经坚持了几天。 如何通过在集合视图中选择单元格来启动popover segue? 主要问题是越过弹出窗口必须锚定到视图的错误。

该方法似乎是在视图中放置一个虚拟popoverAnchorButton (隐藏,禁用),从它创建一个segue到故事板中的弹出视图,将它放在didSelectItemAtIndexPath ,然后[self performSegue] 。 代码如下所示:

- (IBAction)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

    [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
    UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
    CGRect anchorRect = CGRectMake(cell.center.x, cell.center.y, 1.0f, 1.0f);
    self.popoverAnchorButton.frame = anchorRect;
    [self performSegueWithIdentifier:@"popoverSegue" sender:self];
}

这在应用程序的其他位置在表视图中工作,因为故事板允许我在视图中删除按钮,以用作锚点。 但Xcode不允许我将一个按钮或任何其他合适的视图放入故事板中的集合视图中,因此我无法创建segue。 以编程方式创建按钮没有任何帮助,因为我无法从中构建UIStoryboardSegue,并且来自控制器的任何手动segue都会出现与缺少锚点相同的错误。 有任何想法吗?

我认为另一条路径可能是跳过segues并以编程方式实例化popover视图控制器,但这里的包版是一个错误源于我创建的弹出视图(因为我使用的是故事板)没有xib。 我是否必须为此弹出窗口视图创建单独的xib文件? 这是唯一的选择吗?


I've been tracking along with an iPad app using storyboards, and I've been stuck on this for days. How can I initiate a popover segue by selecting a cell in a collection view? The main problem is getting past the error that the popover must be anchored to a view.

The approach seems to be putting a dummy popoverAnchorButton (hidden, disabled) in the view, create a segue from it to the popover view in the storyboard, position it in didSelectItemAtIndexPath, and then [self performSegue]. Code looks like this:

- (IBAction)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

    [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
    UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
    CGRect anchorRect = CGRectMake(cell.center.x, cell.center.y, 1.0f, 1.0f);
    self.popoverAnchorButton.frame = anchorRect;
    [self performSegueWithIdentifier:@"popoverSegue" sender:self];
}

This works elsewhere in the app in a table view, because the storyboard lets me drop a button in the view, to use as an anchor point. But Xcode doesn't let me drop a button or any other suitable view into the collection view in the storyboard, so I can't create the segue. Creating the button programmatically is no help, because I can't build a UIStoryboardSegue from it, and any manual segue from the controller gives the same error about lacking an anchor point. Any ideas?

I think another path could be to skip segues and instantiate the popover view controller programmatically, but the roadblock here is an error stemming from the fact that the popover view I create (since I'm using storyboards) has no xib. Do I have to create a separate xib file just for this popover view? Is that the only option?


原文:https://stackoverflow.com/questions/21566387
更新时间:2024-01-01 13:01

最满意答案

首先,对于FlexibleInstances没有任何问题 - 它只是禁用了标准Haskell的一些限制,这些限制大多是出于历史原因,并且可能使编译器更容易编写。 但是如果你只使用GHC--就像几乎所有人一样 - 那么没有真正的理由不使用FlexibleInstances

UndecidableInstances更具争议性,但有些情况下也可以使用它。

然而,在你的例子中,我没有看到需要定义任何新类型的类! 为什么不直接定义为自由函数,

next, prev :: (Enum a, Bounded a, Eq a) => a -> a
next x | x == maxBound = minBound
       | otherwise     = succ x
prev x | x == minBound = maxBound
       | otherwise     = pred x

好。 可能你的意图是为CyclicEnum添加其他实例,除了通用实例。 但那实际上是不可能的! 即使使用UndecidableInstances 。 它需要OverlappingInstances (或者说Overlappable pragmas),但是重叠的实例并不是你应该使用的东西,因为你可以。


First off, there is nothing wrong at all with FlexibleInstances – it just disables a few restrictions of standard Haskell that are mostly there for historical reasons and perhaps for making compilers easier to write. But if you only use GHC – as almost everybody does – then there's no real reason not to use FlexibleInstances.

UndecidableInstances is more debatable, but there are some cases where it's definitely ok to use that too.

However, in your example, I don't see the need to define any new type class at all! Why not just define, as free functions,

next, prev :: (Enum a, Bounded a, Eq a) => a -> a
next x | x == maxBound = minBound
       | otherwise     = succ x
prev x | x == minBound = maxBound
       | otherwise     = pred x

Well. Probably your intention was to also add other instances for CyclicEnum, apart from the generic one. But that's actually not possible! Even with UndecidableInstances. It needs OverlappingInstances (or rather, Overlappable pragmas), but overlapping instances are really not something you should use just because you can.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)