tags:

views:

57

answers:

1

I want to display a gif image on a subview in iPhone. The sample code glgif shows the gif image on the controller's root view, but when I make the following modifications, the application just crashes:

IBOutlet UIView *gifView;  // gifView is added as a subview of controller's root view

//PlayerView *plView = (PlayerView *)self.view;
PlayerView *plView = (PlayerView *)gifView;

// Load test.gif VideoSource
NSString *str = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"];
FILE *fp = fopen([str UTF8String], "r");
VideoSource *src = VideoSource_init(fp, VIDEOSOURCE_FILE);
src->writeable = false;

// Init video using VideoSource
Video *vid = [[GifVideo alloc] initWithSource:src inContext:[plView context]];
VideoSource_release(src);

// Start if loaded
if (vid) {
    [plView startAnimation:vid];
    [vid release];
    return;
}

// Cleanup if failed
fclose(fp);

Now the app crashes in this line: Video *vid = [[GifVideo alloc] initWithSource:src inContext:[plView context]]; with the error message:-[UIView context]: unrecognized selector sent to instance. Any ideas about how to add the plView to the subview properly?

A: 

Looks like plView is a UIView, not a PlayerView, and does not have a method called "context".

tc.
But why self.view can type cast to PlayerView?
iPhoney
Because it was instantiated as one in the Nib?
tc.