- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个幻灯片菜单。它是使用组件 SWRevealViewController
实现的。为了实现它,我有 1 个主要的 UIViewController
(VC
) - SWRevealViewController
。我有 menu VC
并且我有 push segues
导航到不同的 menu VC
.
对于菜单,我为每个菜单使用带有自定义类的原型(prototype)单元格。
我的问题是我需要调用 unwind segue
去 login VC
,使用 alert view
.为此,我尝试使用常用方法 [self performSegueWithIdentifier:@"unwSegReturnToLogin"sender:self];
从 alert view
得到肯定的回答(在 exit 的自定义类中
单元格)。我在我的 login VC
中声明了这样的方法。我在编译过程中收到错误:
No visible @interface for 'tvcellExitMenuItem' declares
the selector 'performSegueWithIdentifier:sender:'
我怀疑问题是 self
在我的例子中是 table cell
而不是 UIViewController
。
如果是这种情况,如何引用父 VC
?
如果不对,请告诉我逻辑哪里错了。
最佳答案
subview 不应该知道它的父 View Controller 。相反,适合您需要的常见模式是 delegate 模式:为您的单元类定义一个委托(delegate)属性和协议(protocol)。
// your cell class header might look like this
@class MyCellClass;
@protocol MyCellDelegate
- (void)onCellSelected:(MyCellClass *)cell;
@end
@interface MyCellClass
@property (nonatomic, weak) id<MyCellDelegate> delegate;
@end
例如,如果您的 viewController 也是您的 UITableViewDatasource
,那么在 tableView:cellForRowAtIndexPath:
中,您可以将单元格的委托(delegate)设置为 self
,并在委托(delegate)方法中调用 segue 方法。
- (void)onCellSelected:(MyCellClass *)cell
{
// retrieve cell indexPath
NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];
// using indexPth, retrieve cell's data
// push segue with data selected
}
当然,这只是一个例子,还有其他正确的做法。
关于ios - 如何在 Objective-C 中从原型(prototype)单元引用父 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30164364/
我是一名优秀的程序员,十分优秀!