Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy my absolute path for jpg file doesn't work
    primarykey
    data
    text
    <p>I have checked out a few similar questions and didn't find the answer to my question.</p> <p>First part of the question is how to write relative path of file. I didn't get this work but let me move the second part at the moment. Since I couldn't get relative path work, so I tried absolute path. Here is the code I use:</p> <pre><code>NSString *path = [NSString stringWithFormat:@"/Users/my.name/Documents/TestFour/TestFour/Library/file%d.txt", i]; //where i is 1 or 2 //NSString *path = [NSString stringWithFormat:@"./TestFour/Library/file%d.txt", i]; //this relative path didn't work, although TestFour.xcodeproj and TestFour are in the same directory and TestFour has child directory Library and xxx.h and xxx.m files NSString *spath = [path stringByStandardizingPath]; NSLog(@"file is %@", spath); if (spath) { NSString *myText = [NSString stringWithContentsOfFile:spath encoding:NSUTF8StringEncoding error:nil]; //continue, and I got myText .... </code></pre> <p>Now I have a jpg file, say myPic.jpg, in the same directory as above file1.txt, i.e., in the Library folder. I want to load this image into a UIImageView, here is my code, but it failed.</p> <pre><code>NSString *path = @"/Users/my.name/Documents/TestFour/TestFour/Library/myPic.jpg"; NSString *spath = [path stringByStandardizingPath]; </code></pre> <p>[self._bgView setImage:[UIImage imageNamed:spath]];</p> <p>However, I tried a web-based image, which BTW from another related thread, and it worked: [self._bgView setImage:[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]]];</p> <p>So I'm confused why I could read the_same_folder_file1.txt but not load the_same_folder_myPic.jpg</p> <p>And back to the first part, why my relative path didn't work? Not sure if this is related, I was asked and selected the default setting (Group or something like this) when I drag this and other jpg into project. I don't know if I need drag this jpg into the project, but the code didn't work either way, before and after dragging.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload