문제가 있습니다. 어쩌면 내가 잘못된 곳이나 무언가에 무언가를 가지고있을 수도 있지만, 당황 할 수는 없다. 어떤 도움을 주시면 감사하겠습니다.UILabel을 프로그래밍 방식으로 현재 시간에 추가
단순히 시계를 프로그래밍 방식으로 만들어 내 서베이에서만 표시하려고합니다.
내가 만든 하위보기에 표시하려는 업데이터 - (void)와 함께 타이머를 설정했습니다. IBOutlet을 추가하지 않고 그냥 내 스토리 보드에 연결하는 이유는 프로그래밍 방식으로 하위 뷰를 작성하기 때문에 코드만으로 모든 작업을 수행하려고합니다.
알 수없는 식별자 'rightLabel'을 사용하는 'updateTimer'라벨에 오류가 있습니다. 제대로 작동하지 않습니다. HA HA - 어떤 도움을 주시면 대단히 감사하겠습니다! 당신은 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
Ned에게 감사드립니다. 나는 그것을 친구 감사드립니다. –
멋진 rmaddy - 그것에 대해 몰랐습니다. 내 대답을 업데이트했습니다. 다행히 도와 줘서, 션. – Ned