// First VC prepareForSegue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"your segue"])
{
SecondVC *vc = (SecondVC *)segue.destinationViewController;
[SecondVC.timer startTimer:nil];
}
}
// Create Property of NSTimer *timer
// Second VC's Public Methods
@interface SecondVC()
{
NSTimer *_timer;
}
- (void)_timerFired:(NSTimer *)timer;
@end
@implementation SecondVC
- (IBAction)startTimer:(id)sender {
if (!_timer) {
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(_timerFired:)
userInfo:nil
repeats:YES];
}
}
- (void)_timerFired:(NSTimer *)timer {
NSLog(@"Timer fired");
}
Привет, Я хочу нажать кнопку в viewController (A), и это вызовет таймер в viewController (B). Это код, который у меня есть, однако я продолжаю получать "Property 'timer' not found on object of type secondVC "
из этой строки. [SecondVC.timer startTimer:nil];
Спасибо, и я проверил, что оператор import для viewController (A) находится в viewController (B). Как мне разрешить эту ошибку?iOS: Объект не найден на объекте типа
моего fiurst вопрос так же, как первый вопрос вашего компилятора: _where вашей собственности _ как '@property (неатомический, сильный) NSTimer * таймер; '? – holex