gpt4 book ai didi

iphone - 指针类型不兼容

转载 作者:行者123 更新时间:2023-12-01 19:24:31 27 4
gpt4 key购买 nike

在UIWebView的这个子类中,我正在寻找一种创建嵌入式youtube视频的方法。但是,无论我如何编辑此代码(在网上大部分时间都可以找到),它始终会在行中向我发出警告:

self = [[UIWebView alloc] initWithFrame:frame];

我不确定这是因为Xcode 4.2还是iOS 5还是我正在使用self。真的有问题吗?如果是这样,我该如何解决?

整个方法代码:
- (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;
}

最佳答案

您已经分配了内存(由this指向),所以不要再给alloc:

self = [super initWithFrame:frame];

而且,再看一点,您不应该两次 init super。将该语句移到 if,而不是普通的 super init:
if (self = [super initWithFrame:frame]) {...} 

关于iphone - 指针类型不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514837/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com