0
votes

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
    [[self model] setTransitioning:NO];
    [[[[self view]subviews] objectAtIndex:0] removeFromSuperview];
}


How can I tell what kind of viewController controls the subview at index 0? If it's a QuizViewController I need to call a function on it.

Thanks in advance.

Good answers. I don't believe I explained enough. This is a all in a view controller that is a view stack. The view controller adds and deletes views manually with an animated transition. I am not using a navigationController and cannot in this particular instance for other reasons.
Sometimes the views I add are simple UIImageViews. Sometimes they are QuizViews. The QuizViews have a QuizViewController because they need internal functionality. Here are the two functions I use to add the views.

- (void)loadQuiz:(NSInteger )quizNum 

{ if([self quizViewController] != nil) { [self setQuizViewController:nil]; } QuizViewController *quiz = [[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil]; [quiz setUp:quizNum]; [self setQuizViewController:quiz]; [quiz release];

[[self view] addSubview:[[self quizViewController]view]];
[self setSlide1:[[[self view] subviews] objectAtIndex:0]];
[self setSlide2:[[[self view] subviews] objectAtIndex:1]];
[[self slide1] setHidden:NO];
[[self slide2] setHidden:YES];

[self performTransition];

}

- (void)loadImage:(NSString *)slideImage

{

UIImage *tempImg = [UIImage imageWithContentsOfFile:[Utilities localPathForFileName:slideImage]]; UIImageView *temp = [[UIImageView alloc] initWithImage:tempImg]; [[self view] addSubview:temp]; [temp release]; //[topView release]; if ([[[self view]subviews] count] > 2) { //add the 2nd subview //[[[[self view]subviews] objectAtIndex:0] removeFromSuperview]; } [self setSlide1:[[[self view] subviews] objectAtIndex:0]]; [self setSlide2:[[[self view] subviews] objectAtIndex:1]]; [[self slide1] setHidden:NO]; [[self slide2] setHidden:YES]; NSLog(@"%s %d",__FUNCTION__,[[[self view]subviews] count]); [self performTransition];

}

So my question is still, in the animationDidStop function how do I detect if it's a quiz?

3

3 Answers

1
votes

if ([[self view]subviews] objectAtIndex:0] isKindOfClass:CLASS(class)) ...

or isMemberofClass

From memory so you'll have to test it out...

You can also set a tag on the view when you create it, then look for the view when you retrieve it.

someUIView.tag=99;

then

if ( [[self view]subviews] objectAtIndex:0].tag == 99 ) ...

Cheers

0
votes

You maintain one UIViewController (for e.g. UIViewController *currentViewController) object for keeping the track of current view controller.
Now before pushing to the viewcontroller which according to my understanding gets pushed by more than one view controller,you set the currentViewController with the viewController from which you are pushing.
So if you are in QuizViewController and pushing to viewController which controlls subviews,you first set currentController of it and then push it.
subViewController.currentController = self;
[self.navigationController pushViewController:subViewController animated:YES];

0
votes

Views don't inherently have view controllers attached to them, so the way your question is worded doesn't quite make sense. If what you're doing is having a UIView subclass, say QuizView, as a subview and need to know when that is being removed and act on it, then the code would look like this;

-(void) animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)flag 
{ 
    [[self model] setTransitioning:NO]; 
    UIView *subview = [self.view.subviews objectAtIndex:0];
    if([subview isKindOfClass:[QuizView class]])
    {
        [(QuizView*)subview yourFunction];
    }    

    [subview removeFromSuperview];
}

If you mean something different and you can provide some code I might be able to help more, but like I said your original question isn't quite clear to me if this isn't what you mean ;)