Ios UIImage没有';不要加载图像

Ios UIImage没有';不要加载图像,ios,cocoa-touch,uiimage,Ios,Cocoa Touch,Uiimage,下面的代码可以正常工作 scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 1024, 200)]; scrollView1.contentSize = CGSizeMake(2048, 200); scrollView1.showsHorizontalScrollIndicator = YES; scrollView1.scrollEnabled = YES; scrollView1.userInteract

下面的代码可以正常工作

scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 1024, 200)];
scrollView1.contentSize = CGSizeMake(2048, 200);
scrollView1.showsHorizontalScrollIndicator = YES;
scrollView1.scrollEnabled = YES;
scrollView1.userInteractionEnabled = YES;
scrollView1.backgroundColor = [[UIColor alloc] initWithRed:0.5 green:0.8 blue:0.5 alpha:1];
[self.view addSubview:scrollView1];
但这个不是

scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 1024, 200)];
scrollView1.contentSize = CGSizeMake(2048, 200);
scrollView1.showsHorizontalScrollIndicator = YES;
scrollView1.scrollEnabled = YES;
scrollView1.userInteractionEnabled = YES;
scrollView1.backgroundColor = [[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:@"image.jpg"]];
[self.view addSubview:scrollView1];
UIImage有什么问题?在我的整个项目中,UIImage在任何地方都不工作

在我的调试器中,即使在内存分配之后,所有uiimage变量都显示内存地址0*000000000

注意::ScrollView1工作正常,“image.jpg”是正确的参数

[UIImage imageNamed:@"image.jpg"];
像这样试试。这将对你有帮助

编辑:

NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
scrollView1.backgroundColor = [[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:path]];

是的,这已经开始工作了…你知道上面的代码有什么问题吗。为什么变量内存始终显示空。initWithContentsOfFile方法将图像数据加载到内存中并将其标记为可清除。如果数据已清除且需要重新加载,则图像对象将从指定路径再次加载该数据。这里image.jpg不是路径。这只是一个名字。那么根据你的说法,问题的解决方案是什么。。。完整的图像路径?是。您可以使用NSBundle类。我已经更新了。看到这个了吗