在iPhone上将图像从阵列加载到屏幕
我是Xcode新手,我试图从数组中提取一堆图片并将它们放到屏幕上,但通过调试器,我看到我的for循环没有运行在iPhone上将图像从阵列加载到屏幕,iphone,xcode,arrays,debugging,Iphone,Xcode,Arrays,Debugging,我是Xcode新手,我试图从数组中提取一堆图片并将它们放到屏幕上,但通过调试器,我看到我的for循环没有运行 for (int i = 0; i <[imagePaths count]; i++) { NSLog(@"I'm loading a card"); UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 250, 350)]; NSString *imgF
for (int i = 0; i <[imagePaths count]; i++)
{
NSLog(@"I'm loading a card");
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 250, 350)];
NSString *imgFilepath = [[NSBundle mainBundle] pathForResource:[imagePaths objectAtIndex:i] ofType:@"jpg"];
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgFilepath];
[imgView setImage:img];
[self.view addSubview:imgView];
}
for(int i=0;i
我看到我的for循环没有运行
for (int i = 0; i <[imagePaths count]; i++)
{
NSLog(@"I'm loading a card");
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 250, 350)];
NSString *imgFilepath = [[NSBundle mainBundle] pathForResource:[imagePaths objectAtIndex:i] ofType:@"jpg"];
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgFilepath];
[imgView setImage:img];
[self.view addSubview:imgView];
}
在循环之前,使用下面的代码检查您的[imagePaths count]
它将为零。这意味着您的imagepath
数组将为null
NSlog(@"imagePaths count is: %d",[imagePaths count]);
我看到我的for循环没有运行
for (int i = 0; i <[imagePaths count]; i++)
{
NSLog(@"I'm loading a card");
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 250, 350)];
NSString *imgFilepath = [[NSBundle mainBundle] pathForResource:[imagePaths objectAtIndex:i] ofType:@"jpg"];
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgFilepath];
[imgView setImage:img];
[self.view addSubview:imgView];
}
在循环之前,使用下面的代码检查您的[imagePaths count]
它将为零。这意味着您的imagepath
数组将为null
NSlog(@"imagePaths count is: %d",[imagePaths count]);
//检查imagePaths数组包含的内容,如果它包含图像的完整路径,包括文件名和扩展名,则使用以下代码
对于(int i=0;i//检查imagePaths数组包含的内容,如果它包含图像的完整路径,包括文件名和扩展名,则使用以下代码
对于(int i=0;i如果它没有运行,那么ImagePath必须为nil。在它前面添加一个断点,并检查其中是否有任何内容
可能的新手错误:是否正确分配和初始化ImagePath?如果ImagePath未运行,则ImagePath必须为零。在其前面添加一个断点,并检查其中是否有任何内容
可能的新手错误:您是否正确分配和初始化了ImagePath?是否ImagePath
等于nil
?图像是肯定的.jpg不是.png/.jpeg格式?IMO也可能导致问题。是否ImagePath
等于nil
?图像是肯定的。jpg不是.png/.jpeg格式?IMO也可能导致问题。I尝试在for循环上方添加该行代码,但它给了我2个错误。Apple Mach-o链接器错误“\u NSlog”,引用自ViewController中的:-[ViewController viewDidLoad]。o和Apple Mach-o链接器错误,链接器命令失败,退出代码为1(使用-v查看调用)有什么想法吗?有。使用NSlog(@“ImagePath计数为:%d”,[imagePaths count]);代码现在运行正常,但计数为0yup..原因是,,,,我尝试在for循环上方添加那行代码,但它给了我2个错误。Apple Mach-o链接器错误“\u NSlog”,引用自:-[ViewController viewDidLoad]在ViewController.o和Apple Mach-o链接器错误中,链接器命令失败,退出代码为1(使用-v查看调用)有什么想法吗?是。使用NSLog(@“imagePaths计数为:%d”,[imagePaths计数]);代码现在运行正常,但计数为0是..原因是,,,,你能解释完整的noob吗?哈哈,你能解释完整的noob吗?哈哈