好吧,我的错误,我之前认为我的 ivar 没有正确更改。我错了(并且得到了一些反对票)。抱歉,真正的问题是我一直在错误地调用它。我现在发布所有代码,我会让你看一下。
我的第一堂课:
类一.h:
@interface DetailPageController : UIPageViewController
{
BOOL isChromeHidden_;
}
- (void)toggleChromeDisplay;
@end
classOne.m:
@interface DetailPageController ()
@end
@implementation DetailPageController
- (void)toggleChromeDisplay
{
[self toggleChrome:!isChromeHidden_];
}
- (void)toggleChrome:(BOOL)hide
{
//Find chrome value
isChromeHidden_ = !isChromeHidden_;
NSLog(isChromeHidden_ ? @"YES" : @"NO");
}
@end
从我收到的评论来看,我相信这些都不是真正的问题,它在下面。
classTwo.h:(没有声明)
类二.m:
@interface classTwo ()
@end
@implementation classTwo
//Touches Control
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view]) {
if ([touch tapCount] == 2) {
NSLog(@"double touched");
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toggleChromeDisplay) object:nil];
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view]) {
if ([touch tapCount] == 1) {
NSLog(@"single touch");
[self performSelector:@selector(toggleChromeDisplay) withObject:nil afterDelay:0.5];
}
}
}
- (void)toggleChromeDisplay
{
DetailPageController *pageController = [[DetailPageController alloc] init];
[pageController toggleChromeDisplay];
}
@end
再次,对上一篇文章感到抱歉,我曾认为这是该方法的问题,但实际上是我所说的方式。
我被迫做的是在处理触摸区域的控制器中实现触摸,但我在另一个中有用于 chrome(导航栏和工具栏)的方法。
总体问题 为什么每次我在 classTwo 中调用 toggleChromeDisplay 方法时,我总是从 classOne 中的 ivar 中得到相同的 NO?
我为 classTwo.h 尝试过的内容:
#import "DetailPageController.h"
@interface classTwo : UIViewController
{
DetailPageController *detailPageController_;
}
@property (nonatomic, assign) DetailPageController *detailPageController;
@end
我修改后的代码:
在我的 classTwo.h 中:
#import "DetailPageController.h"
@interface PhotoViewController : UIViewController
{
DetailPageController *detailPageController_;
}
@property (nonatomic, strong) DetailPageController *detailPageController;
@end
类二.m:
#import "classTwo.h"
@interface classTwo ()
@end
@implementation classTwo
@synthesize detailPageController = detailPageController_;
//Touches Control
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view]) {
if ([touch tapCount] == 2) {
NSLog(@"double touched");
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(toggleChromeDisplay) object:nil];
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view]) {
if ([touch tapCount] == 1) {
NSLog(@"single touch");
[self performSelector:@selector(toggleChromeDisplay) withObject:nil afterDelay:0];
}
}
}
- (void)toggleChromeDisplay
{
[self.detailPageController toggleChromeDisplay];
}
@end