Xcode 4.2 Objective C 中的警告

发布于 2024-12-28 18:41:43 字数 1456 浏览 0 评论 0原文

我创建了一个 iPad 应用程序,在其中我从 URL 获取数据, 当我编写此代码时,它向我显示此警告 initWithContentsOfURL 已弃用

这是代码片段,

NSString *mainstr;

NSURL *urlr=[NSURL URLWithString:@"http://abc.com/default.aspx?id=G"];
NSURLRequest *reqr=[NSURLRequest requestWithURL:urlr];
[webViewq loadRequest:reqr];

mainstr=[[NSMutableString alloc]initWithContentsOfURL:urlr]; 

也在 tableView 中向我显示此警告,initWithFrame:reuseIdentifier: 已弃用

这里是代码片段,其中我在每一行中创建一个标签

static NSString *CellIdentifier=@"Cell"; 

if(cell == nil){


            cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease];

            CGRect frame;
            frame.origin.x = 0; 
            frame.origin.y = 0;
            frame.size.height = 40;
            frame.size.width = 180;


            UILabel *capitalLabelI = [[UILabel alloc] initWithFrame:frame];
            capitalLabelI.tag = CapitalTag;
            capitalLabelI.font=[UIFont systemFontOfSize:16.0];

}
capitalLabelI.text=[@" " stringByAppendingString:[a objectAtIndex:indexPath.row]];

return cell;

,当我调用多个参数化方法时,它会向我显示此警告,

方法名称:

-(void)recentquote:(NSString *)sym:(int)i

调用语法:

[self recentquote:l3:i];

警告:

未找到实例方法 '-recentquote::' (返回类型默认to 'id')'

帮帮我!!

提前致谢!!

i created an iPad application, in which i am fetching data from URL,
when i write this code it shows me this warning initWithContentsOfURL is deprecated

here is the code snippet,

NSString *mainstr;

NSURL *urlr=[NSURL URLWithString:@"http://abc.com/default.aspx?id=G"];
NSURLRequest *reqr=[NSURLRequest requestWithURL:urlr];
[webViewq loadRequest:reqr];

mainstr=[[NSMutableString alloc]initWithContentsOfURL:urlr]; 

also in tableView it shows me this warning,initWithFrame:reuseIdentifier: is deprecated

here is the code snippet, in which i am creating one label inside each row

static NSString *CellIdentifier=@"Cell"; 

if(cell == nil){


            cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease];

            CGRect frame;
            frame.origin.x = 0; 
            frame.origin.y = 0;
            frame.size.height = 40;
            frame.size.width = 180;


            UILabel *capitalLabelI = [[UILabel alloc] initWithFrame:frame];
            capitalLabelI.tag = CapitalTag;
            capitalLabelI.font=[UIFont systemFontOfSize:16.0];

}
capitalLabelI.text=[@" " stringByAppendingString:[a objectAtIndex:indexPath.row]];

return cell;

and when i call multiple parametrized method, it shows me this warning,

method name:

-(void)recentquote:(NSString *)sym:(int)i

call syntex:

[self recentquote:l3:i];

warning:

Instance method '-recentquote::' not found (return type default to 'id')'

Help me guys !!

Thanks In Advance !!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱世争霸 2025-01-04 18:41:43

而不是

initWithContentsOfURL 

使用:

initWithContentsOfFile:encoding:error: 

initWithContentsOfFile:usedEncoding:error: 

而不是

initWithFrame:reuseIdentifier: 

使用:

initWithStyle:reuseIdentifier:

您应该将以下声明更改

-(void)recentquote:(NSString *)sym:(int)i

为:

-(void)recentquote:(NSString *)sym someArg:(int)i

看来您对 Objective-C 和 iPad 开发真的很陌生,我强烈建议您阅读: https://stackoverflow.com/questions/332039/getting-started-with-iphone-development

instead of

initWithContentsOfURL 

use:

initWithContentsOfFile:encoding:error: 

or

initWithContentsOfFile:usedEncoding:error: 

instead of

initWithFrame:reuseIdentifier: 

use:

initWithStyle:reuseIdentifier:

And you should change the declaration of:

-(void)recentquote:(NSString *)sym:(int)i

to:

-(void)recentquote:(NSString *)sym someArg:(int)i

Seems like you are really new to objective-c and iPad development, I strongly recommand you to read: https://stackoverflow.com/questions/332039/getting-started-with-iphone-development

小情绪 2025-01-04 18:41:43

调用语法应该是

[self recentquote:l3 :i];

(注意之间的空格),我建议无论如何重命名你的函数。

当它说它已被弃用时,它只是意味着在未来的某个时候,Apple 可能会一起删除此方法,不再支持它。因此,将您的更改

cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease];

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                            reuseIdentifier:CellIdentifier] autorelease];

检查文档以获取可用样式以及它的含义

编辑:

我建议更改它,也许

- (void)recentQuote:(NSString *)quote withIndex:(int)index; 

然后调用它使用

[self recentQuote:@"OK" withIndex:2];

the call syntax should be

[self recentquote:l3 :i];

(note at the space in between), I suggest renaming your function anyway.

when it say it's deprecated, it simply means some time in the future, Apple might remove this method all together, it's not longer supported. So change your

cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease];

to

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                            reuseIdentifier:CellIdentifier] autorelease];

Check the documentation for available style and what it means

EDIT :

I suggest changing it, maybe to

- (void)recentQuote:(NSString *)quote withIndex:(int)index; 

then to call it use

[self recentQuote:@"OK" withIndex:2];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文