0

Hi people at StackOverflow

I can't get my image to show up on my SpringBoard

in my Tweak.xm SpringBoard is hooked, my UILabel shows up but my UIImage won't show up...

For the UIImage I tried to follow this question UIImage may not respond to imageWithContentsofFile

But I don't know what imageWithContents**Of**File meant stated in the answer so I'm still stuck with this code:

 [basePic setImage:[UIImage imageWithContentsOfFile:@"layout/private/var/stash/subject4stw/weatherspring/pic.png"]];
basePic.frame = CGRectMake(21.0,0.0,320.0,98.0);
[self.viewThing addSubview:basePic];
[basePic release];

Can someone help me with this?

Also theos doesn't give any warnings or errors when compiling, it compiles and runs sucessfully

I tried

NSLog(@"%@",[UIImage imageWithContentsOfFile:@"/private/var/stash/subject4stw/weatherspring/pic.png"]);

and I got output, but when I try to let it show up on my SpringBoard it just stays empty

Community
  • 1
  • 1
Subject
  • 11
  • 3
  • did you try [basePic setImage:[UIImage imageWithContentsOfFile:@"pic.png']? – santhu Jan 19 '14 at 15:17
  • `NSLog(@"%@",[UIImage imageWithConentsOfFile:@"layout/private/var/stash/subject4stw/weatherspring/pic.png"]);` What does this say? – nhgrif Jan 19 '14 at 15:18
  • In the linked answer `imageWithContents**Of**File` was emphasizing the uppercase `O` versus lowercase `o`, which isn't a problem your code has. – nhgrif Jan 19 '14 at 15:20
  • @nhgrif thanks for your answer and erm... Where am I supposed to see the output? I tried deviceconsole but can't find it. – Subject Jan 19 '14 at 16:14
  • @santhu this is a tweak so I must keep that type of directory tree – Subject Jan 19 '14 at 16:20
  • @nhgrif found it! Unfortunately it returns (null) – Subject Jan 19 '14 at 16:54
  • If it's returning `(null)`, then it's not finding a file at that path. – nhgrif Jan 19 '14 at 16:59
  • @nhgrif nope pointed the file from the root (/) and then my output was '' means it was found, right? But the pic still doesn't show up on my screen – Subject Jan 19 '14 at 18:06
  • Can you get `NSLog(@"%@",[UIImage imageWithConentsOfFile:@"layout/private/var/stash/subject4stw/weatherspring/pic.‌​png"]);` to return a value in the same execution of code that doesn't display the image? – nhgrif Jan 19 '14 at 18:07
  • I don't really understand what you mean, I tried instead of layout/ this `NSLog(@"%@",[UIImage imageWithConentsOfFile:@"/private/var/stash/subject4stw/weatherspring/pic.‌​‌​png"]);` and I got output... but When I give my pic the same props so w/o layout/ as well it won't show up – Subject Jan 19 '14 at 18:11

1 Answers1

0

You need to specify the path of the image as it appears in the filesystem, not as it appears in your project directory.

Instead of this:

[basePic setImage:[UIImage imageWithContentsOfFile:@"layout/private/var/stash/subject4stw/weatherspring/pic.png"]];

You would do something like this:

[basePic setImage:[UIImage imageWithContentsOfFile:@"/private/var/stash/subject4stw/weatherspring/pic.png"]];

However, I would not recommend putting any resources in this directory. As far as I know, the names of the folders in ./stash are auto-generated, and therefore may change with time or the device using the tweak. A constant path which you know is commonly used would suit better, so that line would now look something like this:

[basePic setImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/WeatherSpring/pic.png"]];
Phillip
  • 1,205
  • 3
  • 15
  • 22