我有一个问题。也许我把某些东西放错了地方,但是我真的搞不清楚!任何帮助都将不胜感激。
我试图通过编程方式制作一个时钟,仅在我的子视图中显示。
我设置了一个计时器和一个更新程序-(void),我想在其中创建的子视图中显示它。我正在以编程方式构建子视图,这就是不添加IBOutlet并只在我的storyboard中连接它的原因-我正在尝试使用代码完成所有操作。
我在updateTimer标签上得到了一个错误,该错误说-使用未声明的标识符'rightLabel',对我来说这根本行不通。哈哈-任何帮助都将不胜感激!
.h
我试图通过编程方式制作一个时钟,仅在我的子视图中显示。
我设置了一个计时器和一个更新程序-(void),我想在其中创建的子视图中显示它。我正在以编程方式构建子视图,这就是不添加IBOutlet并只在我的storyboard中连接它的原因-我正在尝试使用代码完成所有操作。
我在updateTimer标签上得到了一个错误,该错误说-使用未声明的标识符'rightLabel',对我来说这根本行不通。哈哈-任何帮助都将不胜感激!
.h
@interface DemoRootViewController : UIViewController <PaperFoldViewDelegate> {
NSTimer *timer;
}
@property (nonatomic, strong) UIView *rightView;
-(void)updateTimer;
.m
- (id)init
{
self = [super init];
if (self) {
//Timer Setup
timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
//PaperFold Setup
_paperFoldView = [[PaperFoldView alloc] initWithFrame:CGRectMake(0,0,[self.view bounds].size.width,[self.view bounds].size.height)];
[_paperFoldView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[self.view addSubview:_paperFoldView];
//Setup Subview
_rightView = [[UIView alloc] initWithFrame:CGRectMake(0,0,240,[self.view bounds].size.height)];
//Setup UILabel
UILabel *rightLabel = [[UILabel alloc] initWithFrame:_rightView.frame];
[_rightView addSubview:rightLabel];
//Using PaperFold Framework to Add the Subview (this works fine)
[_paperFoldView setRightFoldContentView:_rightView foldCount:2 pullFactor:1];
}
return self;
}
-(void)updateTimer {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm:ss"];
//This is where I get my error "Use of Undeclared Identifier 'rightLabel'
rightLabel.text = [formatter stringFromDate:[NSDate date]];
}
@end
@implementation
块中。类扩展用于(现在已经不需要的)前向方法声明和私有属性。它也可以用于指示类符合协议。 - rmaddy