In this subclass of UIWebView, I am looking to set up a method to create an embedded youtube video. However, no matter how I edit this code (which I found most of online), it is always giving me a warning at the line:
self = [[UIWebView alloc] initWithFrame:frame];
Im not sure whether this is because of Xcode 4.2 or iOS 5 or the fact that I am using self. Is there actually something wrong? If so, how might I fix it?
Entire method code:
- (videosView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
{
if (self = [super init])
{
// Create webview with requested frame size
self = [[UIWebView alloc] initWithFrame:frame];
// HTML to embed YouTube video
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
// Populate HTML with the URL and requested frame size
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];
// Load the html into the webview
[self loadHTMLString:html baseURL:nil];
[self setUserInteractionEnabled:YES];
}
return self;
}
You already have the memory allocated (pointed to by
this), so don’tallocmore:And, looking a bit more, you shouldn’t
initsuper twice. Move that statement into theif, instead of the plainsuper init: