Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ctyhntr

macrumors 6502
Original poster
Jul 21, 2010
301
0
I have two IBOutlets pulling from the same NSMutable Array. The NSMutable is storing the name of png files. file1.png, file2.png, etc

Basically, its a pickerview and showing a picture and the file name (UIImageView and UILabel).

The UILabel IBOutlet for the filename works, displaying the filename, but not UIImageView IBOutlet but crashes with a SIGABRT.

[labelRace setText:[arrRace objectAtIndex:row]];
The UILabel returns the filename, file1.png, file2png, etc

[imageRace setImage:[arrRace objectAtIndex:row]];
This doesn't work, instead the app crashes I get a SIGABRT

and neither does this
[imageRace setImage:[UIImage imageNamed:mad: "%@",arrRace objectAtIndex:row]];

Hardcoding works, and confirms that the file is registered as a resource.
[imageRace setImage: [UIImage imageName:mad:"file1.png"]];

Any ideas what I'm doing wrong?
 

ulbador

macrumors 68000
Feb 11, 2010
1,554
0
and neither does this
[imageRace setImage:[UIImage imageNamed:mad: "%@",arrRace objectAtIndex:row]];

That should work. You just need a stringWithFormat to get the name into it

[imageRace setImage:[UIImage imageNamed:[NSSttring stringWithFormat: "%@",[arrRace objectAtIndex:row]]]];
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
That should work. You just need a stringWithFormat to get the name into it

[imageRace setImage:[UIImage imageNamed:[NSSttring stringWithFormat: "%@",[arrRace objectAtIndex:row]]]];

That's redundantly redundant. It also has syntax problems.

If the array contains NSString objects, then this should be the NSString directly from the array:
Code:
[arrRace objectAtIndex:row]
and this will be the image:
Code:
[UIImage imageNamed:[arrRace objectAtIndex:row]]

There's no need to go through the extra level of a formatted string. Worst-case:
Code:
[[arrRace objectAtIndex:row] description]
gets you the same NSString * as:
Code:
[NSString stringWithFormat: @"%@",[arrRace objectAtIndex:row]]
because %@ sends any object a description message. See the reference doc for String Format Specifiers.

Or you could use the fact that you just assigned the correct name to a UILabel's text property:
Code:
[imageRace setImage:[UIImage imageNamed:labelRace.text]];
 

RonC

macrumors regular
Oct 18, 2007
108
0
Chicago-area
The UILabel IBOutlet for the filename works, displaying the filename, but not UIImageView IBOutlet but crashes with a SIGABRT.

[labelRace setText:[arrRace objectAtIndex:row]];
The UILabel returns the filename, file1.png, file2png, etc

[imageRace setImage:[arrRace objectAtIndex:row]];
This doesn't work, instead the app crashes I get a SIGABRT

...

Hardcoding works, and confirms that the file is registered as a resource.
[imageRace setImage: [UIImage imageName:mad:"file1.png"]];

Any ideas what I'm doing wrong?

2 thoughts on 2 different problems:

Problem 1: This code
Code:
[imageRace setImage:[arrRace objectAtIndex:row]];
is wrong.

imageRace.image is a UIImage, not a NSString. Change it to look like
Code:
imageRace setImage: [UIImage imageNamed:[arrRace objectAtIndex:row]];

Problem 2: The string doesn't what you think it contains.

The text ' file1.png', 'file1.png', and 'file1.png ' all look the same in the label, but they're not all names of files. Stick a NSLog statement near either of those IBOutlet messages to see the full context of the string, something like
Code:
NSLog(@"The string at row %d is '%@'.",row,[arrRace objectAtIndex:row]);

Ron C
 
Last edited:

ctyhntr

macrumors 6502
Original poster
Jul 21, 2010
301
0
RonC, chown33, and ulbador,

Thank you for your help. I was able to fix it. Later, I'll get a cup of coffee and sit down to compare, so I can figure out why I didn't get it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.