在 iPhone 中的 imageView 中设置图像时出错

发布于 2024-10-31 21:23:35 字数 631 浏览 2 评论 0原文

我已经编写了一段用于设置 imageview 的代码...根据单击的按钮...但我的问题是当我按下按钮时它给了我这样的错误...函数 ImageNamed 的参数太多...执行此操作时line...

UIImage* photo = [UIImage imageNamed:@"robort %d.jpg",x];

整个代码是...

-(void)buttonClicked:(UIButton*)button
{
NSLog(@"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
UIImage* photo = [UIImage imageNamed:@"robort %d.jpg",x];
NSLog(@"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView]; }

I have written a code for setting imageview ...as per the button clicked...but my problem is when i press the button it is giving me the error like...too many arguments to function ImageNamed...while executing this line...

UIImage* photo = [UIImage imageNamed:@"robort %d.jpg",x];

the whole code is....

-(void)buttonClicked:(UIButton*)button
{
NSLog(@"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
UIImage* photo = [UIImage imageNamed:@"robort %d.jpg",x];
NSLog(@"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView]; }

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

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

发布评论

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

评论(4

执笔绘流年 2024-11-07 21:23:35

使用 UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort de nero%d.jpg",x]];

干杯:)

use UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort de nero%d.jpg",x]];

cheers :)

丢了幸福的猪 2024-11-07 21:23:35

试试这个

-(void)buttonClicked:(UIButton*)button
{
NSLog(@"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
NSString *imageName = [NSString stringWithFormat:@"robort %d.jpg",x];
UIImage* photo = [UIImage imageNamed:imageName];
NSLog(@"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView]; 
}

Try this

-(void)buttonClicked:(UIButton*)button
{
NSLog(@"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
NSString *imageName = [NSString stringWithFormat:@"robort %d.jpg",x];
UIImage* photo = [UIImage imageNamed:imageName];
NSLog(@"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView]; 
}
九八野马 2024-11-07 21:23:35

您需要使用:

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];

You need to use:

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];
看海 2024-11-07 21:23:35

用这个

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];

Use this

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文