如何在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 indidSelectItemAtIndexPath
, 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
最满意答案
首先,对于
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 useFlexibleInstances
.
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 withUndecidableInstances
. It needsOverlappingInstances
(or rather,Overlappable
pragmas), but overlapping instances are really not something you should use just because you can.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
看起来这可能正在进行中。 http://ghc.haskell.org/trac/ghc/ticket/7633 (及相关资料: http : //ghc.haskell.org/trac/ghc/ticket/6028 ) 看起来它已经集成在GHC 7.8.1中。 UPDATE 这是GHC 7.8中的最小编译指示 。 It looks like this may be in progress. http://ghc.haskell.org/trac/ghc/ticket/7633 (and related ...
-
不,这不合法。 你有一个扩展抽象类的具体类( C未声明为抽象),但没有提供其方法的实现。 目前还不清楚为什么你认为这应该或者可能是合法的 - 你应该考虑这是否会对你对遗传的理解产生更广泛的影响,而不仅仅是这个具体的案例。 C与B完全分开。 它们可以具有完全不同的状态 - 例如,B可以使用仅存在于B的实例中的某个状态来实现method() 。 重要的是要理解C的实例不是 B的实例。 如果您希望它继承其行为,则应该使C子类B而不是A No, it's not legal. You've got a concre ...
-
您可以定义具有相同名称的函数(和运算符),只要它们位于不同的模块中即可。 所以有Prelude.== (默认一个)和你的(比如, My.== )。 在My.==的默认定义中,编译器不知道使用哪个。 修复是微不足道的丑陋: {-# LANGUAGE DefaultSignatures #-} module My where class (Eq a) => Foo a where size :: a -> Int (==) :: a -> a -> Bool (==) s t = (size s) ...
-
这是Explosion在其声明之外的简单扩展。 这只是一个含义 ,我认为没有特别的理由这样做。 It's a simple extension of Explosion outside its declaration. It is just an implication, I don't think there has to be particular reason for doing it.
-
首先,对于FlexibleInstances没有任何问题 - 它只是禁用了标准Haskell的一些限制,这些限制大多是出于历史原因,并且可能使编译器更容易编写。 但是如果你只使用GHC--就像几乎所有人一样 - 那么没有真正的理由不使用FlexibleInstances 。 UndecidableInstances更具争议性,但有些情况下也可以使用它。 然而,在你的例子中,我没有看到需要定义任何新类型的类! 为什么不直接定义为自由函数, next, prev :: (Enum a, Bounded a, E ...
-
如果你不想像Daniel建议的那样拥有泛型类,你也可以告诉编译器T使用where子句来限制泛型类型: public abstract class SomeBase { public List
BuildList (int v1, int v2) where T: BusinessThing { var results = new List (); for (int i = v1; i < v2; i++) { ... -
是否可以在另一个子类中声明子类对象?(Is it possible to declare subclass objects in another subclass? [duplicate])[2022-06-03]
当然。 Square与其他任何课程没什么特别不同。 事实上它碰巧是另一个类的子类,在这个上下文中没有实际的区别。 就像你可以拥有: class Shape { ... }; class Square { .. }; class Cube: public Shape { ... Square sq1; ... }; 你也可以: class Shape { ... }; class Square : public Shape { .. }; class Cube: public Shape { ... ... -
转发声明子类(Forward Declare a Subclass)[2022-03-21]
你需要在头文件中声明A例如Ah并将该文件包含到B.cpp和C.cpp中,如果你在A有一些非inline函数(在A声明中定义的函数是隐式inline ),你应该创建A. cpp,包括那里的Ah,并在A.cpp中定义这些函数 You need to declare A in header file for example A.h and include that file into B.cpp and C.cpp, also if you have some non inline functions in A ...