Setting the button display method

I want this method to check if the condition is true, and then specify a specific button (button) to indicate the images I specified. Here is the code.

-(void)canAfford:(float) f: (UIButton*)button { if([self playerHas:(f)] == YES) { [button setImage:[UIImage imageNamed:nil] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"ButtonBGclicked.png"] forState:UIControlStateHighlighted]; } else { [button setImage:[UIImage imageNamed:@"ButtonBG.png"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:nil] forState:UIControlStateHighlighted]; } } 

Here is the error I am getting.

 2013-09-22 10:35:39.985 Tapple[15663:a0b] CUICatalog: Invalid asset name supplied: , or invalid scale factor: 1.000000 
+7
ios objective-c iphone cocoa-touch uibutton
source share
6 answers

You call [UIImage imageNamed:@""] or [UIImage imageNamed:nil] . No image will match an empty string. If you are trying to clear the image, go nil instead of calling imageNamed:

Try it (updated source code including @Kyle Fang comment):

 - (void)canAfford:(float) f: (UIButton*)button { if([self playerHas:(f)] == YES) { [button setImage:nil forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"ButtonBGclicked.png"] forState:UIControlStateHighlighted]; } else { [button setImage:[UIImage imageNamed:@"ButtonBG.png"] forState:UIControlStateNormal]; [button setImage:nil forState:UIControlStateHighlighted]; } } 
+13
source share

The best way to use breakpoints to find a specific call that calls + [UIImage imagenamed:] to generate an error is to use a Symbolic breakpoint.

Open the Breakpoints Navigator and click the + button in the lower left. Select "Add Symbolic Breakpoint ...". Then edit the breakpoint to have the following settings:

Symbol: + [UIImage imageNamed:] Condition: $ r2 == nil

The condition test register is r2, which points to an argument to the imageNamed: method for the method's null argument. You can also set the condition (BOOL) [(NSString *) $ r2 isEqualToString: @ ""] if you want to see if an empty string was used as an argument. Please note that the r2 register is present only in case of debugging on the device. The simulator will use a different named register since it works in the x86 architecture.

When the conditions are met, the debugger breaks into the assembler code of the UIKit library, but you can find the source of the call in the trace of the thread stack.

You need only one breakpoint to check your entire code base for the source of the call.

+5
source share

I got the same error "CUICatalog: invalid asset name: or invalid scale factor: 2.000000" after using the asset catalog new in Xcode 5.

After some debugging, I found that the cause of this error was passing the argument "nil" or an empty string @ "to the class method [UIImage imageNamed:]. Even passing a file name that was not in the set did not cause this error.

So I agree that (apparently got my vote) for the fix. Now, if you did what you suggested and still got the error, make sure you look at your code and maybe place a breakpoint wherever you call [UIImage imageNamed:] and see if you pass zero or empty string as an argument.

FYI, to create a breakpoint, simply click on the left edge of the code editor and add a blue breakpoint. Then right-click on the breakpoint and select "Edit breakpoint .." in the menu that appears. Then in the Condition field, enter something like the following:

(! imageFileName || [imageFileName isEqualToString: @ ""])

where imageFileName is a string representing the image file you are trying to load.

+1
source share

I found that the source of this problem for me was that the array that I was receiving data from the image definition was marked weak, nonatomic and cleared of me.

Installing an array of data sources as nonatomic, retain fixes this elusive problem.

+1
source share

1) Add Symbolic BreakPoint after clicking the plus button. plus sign at the bottom 2) add this boolean string to check for empty string boolean line for condition 3) it was added automatically (not sure after the build or not), so I edited to add a condition check for nil

Hope this can help a little more, including me.

+1
source share

Read this only if you are using IB or storyboards!

I had this problem after I set the image for the UIImageView in the storyboard and then changed that image name in the asset directory. The ImageView in the storyboard was still with this image, although the attribute inspector for viewing images in the image field said "Unknown image". Everything worked fine, because later on I set up the image through code, with the exception of the annoying log.

Wow, it’s like overuse of the word “image,” I hope this helps someone.

0
source share

All Articles