I'm trying to make menu with custom font, but it doesn't seem to work.
Here is the code:
- (id) init
{
if (self = [super init])
{
CGSize size = [[CCDirector sharedDirector] winSize];
[CCMenuItemFont setFontName:#"PC Senior Regular"];
[CCMenuItemFont setFontSize:18];
CCMenuItemFont *menu1 = [CCMenuItemFont itemFromString:#"Music ON" target:self selector:#selector(musicToggle)];
CCMenuItemFont *menu2 = [CCMenuItemFont itemFromString:#"Back" target:self selector:#selector(back)];
CCMenu *menu = [CCMenu menuWithItems:menu1, menu2, nil];
[menu setPosition:ccp(size.width / 2 , size.height / 2)];
[menu alignItemsVertically];
[self addChild:menu];
}
Here is the code in my info.plist:
<key>UIAppFonts</key>
<array>
<string>PC Senior Regular.ttf</string>
<string>senior.ttf</string>
</array>
Exception:
2012-07-27 05:42:35.369 Busterball[16089:10a03] In options
2012-07-27 05:42:35.371 Busterball[16089:10a03] -[__NSCFConstantString sizeWithZFont:]: unrecognized selector sent to instance 0xb0670
2012-07-27 05:42:35.372 Busterball[16089:10a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString sizeWithZFont:]: unrecognized selector sent to instance 0xb0670'
I have tried using senior.ttf, just senior, etc.
Both fonts are added as targets for the project. I double checked for correct type case.
What is going wrong?
Have you tried something like this?
CCLabelTTF *label = [CCLabelTTF labelWithString:"Some Text" fontName:#"MyFont.TTF" fontSize:24.0];
CCMenuItem *item = [CCMenuItemLabel itemWithLabel:label target:self selector:#selector(myFunction)];
CCMenu *menu = [CCMenu menuWithItems:item];
[self addChild:menu];
Your info.plist looks right, and this code has worked for me. That said, I do recommend setting breakpoints and trying to find where your error is coming from.
An invalid argument exception means that you are trying to use a method that is not recognized. The problem is your sizeWithZFont method. I have tried to search in the cocos2d documentation and that is not a method in there.
Related
I have an NSImage in an NSPanel in which I'd like to get the mouse X, Y co-ords.
If I set the NSImage layer content withlayer.content =splitNSImage (where splitNSImage is an NSImage created from a URL)and then
NSRect layerBounds = [layer bounds];
NSTrackingAreaOptions options = (NSTrackingActiveAlways|NStrackingInVisibleRect|NSTrackingMouseEnter|
NSTrackingMouseExit|NSTrackingMouseMoved);
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:layerBounds owner:self userinfo:nil];
[[layer contents] addTrackingArea:trackingArea];
I get a runtime error "Thread 1: "-[NSImage addTrackingArea:]: Unrecognised selector sent to instance 0x600003335400" on the last line.
If I use the use [NSPanel contentView] instead of [layer contents] it works OK but gives the mouse co-ords (in the MouseMoved event) in the panel rather than the imageView
I'm adding a gradient layer and attaching name to it.
Later on when I try to remove it by searching for that name, my app crashes. Here's the code I'm using.
CAGradientLayer* gradient = [CAGradientLayer layer];
gradient.colors = [NSArray arrayWithObjects:
..... setting up gradient.....
gradientLayer.name = #"GradientLayer";
[self.myView.layer insertSublayer:gradient atIndex:0];
Later on I'm trying to remove it.
for (CALayer *layer in self.myView.layer.sublayers) {
if ([layer.name isEqualToString:#"GradientLayer"])
{
[layer removeFromSuperlayer];
}
}
It crashes when it tries to remove the sublayer.
Your loop mutates self.myView.layer.sublayers while it is being enumerated.
Add break; after [layer removeFromSuperLayer]; to stop enumerating, then you will be fine.
I'm attempting to build a simple app in Objective C, utilizing an attributes Dictionary in my AppDelegate module to allow me to customize the look of various navigation items of my story layout.
The code builds fine with no errors but as it deploys onto my test device I get a SIGABRT.
I'm using latest version Xcode(9.2); storyboards are all set to "Builds for iOS 8.2 and Later"; Deployment Target is set at 8.1.
I had utilized UITextAttributeTextShadowColor, nil in my code without issues, but that is deprecated since iOS 7.0 so I updated it to NSShadowAttributeName, nil and now it won't work.
What am I doing wrong?
The specific SIGABRT error reads: Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor
shadowColor]: unrecognized selector sent to instance 0x1d447cf00'.
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:170.0/255.0 green:21.0/255.0 blue:29.0/255.0 alpha:1.0],
NSForegroundColorAttributeName,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0],
NSShadowAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes: attribs];
[[UIBarButtonItem appearance] setTitleTextAttributes: attribs forState:UIControlStateNormal];
return YES;
}
You need to do your code updation like this :
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blackColor];
shadow.shadowOffset = CGSizeMake(1, 0);
NSDictionary * attribs = #{NSForegroundColorAttributeName: [UIColor whiteColor],
NSShadowAttributeName: shadow,
NSFontAttributeName: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes: attribs];
This will solve your problem of crash.
Documentation: of NSShadowAttributeName:
The value of this attribute is an NSShadow object. The default value
of this property is nil.
Clearly that's not what you do. You gave a UIColor object.
And that's exactly what is saying the error:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor
shadowColor]: unrecognized selector sent to instance 0x1d447cf00'
It's saying: I tried to call a method shadowColor on a UIDeviceRGBColor (surely a cluster for UIColor) object. But since it doesn't know that method (~ selector, for your level that's the case), I crashed.
Clearly, that's where you can get suspicious. shadowColor that's an available method on NSShadow object. Maybe I did something wrong. And reading the doc you'll know it's the case.
So put a NSShadow object instead of a UIColor one for the value corresponding.
I am trying to add a UIView to a UITableView's header, then, using the NSLayoutConstraints I want to give it a height.
I've looked through the Apple Docs and the WWDC 2012 videos but I cannot find this particular error anywhere!
I have the following code:
- (UIImageView *)logoImageView
{
if (!_logoImageView) {
_logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"logo"]];
[_logoImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
}
return _logoImageView;
}
... in viewDidLoad
UIView *tableHeaderView = [[UIView alloc] init];
tableHeaderView.translatesAutoresizingMaskIntoConstraints = NO;
[tableHeaderView addSubview:self.logoImageView];
[self.tableView setTableHeaderView:tableHeaderView];
NSDictionary *constraintViews = #{#"tableView" : self.tableView, #"tableHeaderView" : tableHeaderView, #"logoImageView" : self.logoImageView};
[self.tableView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:[tableHeaderView(50)]"
options:0
metrics:nil
views:constraintViews]];
However when I run it I get the following error:
2012-10-08 16:31:34.559 myApp[6934:c07] *** Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776
2012-10-08 16:31:34.561 myApp[6934:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'
*** First throw call stack:
(0x199b012 0x17c0e7e 0x199ae78 0x1256f35 0x7589ef 0x17d46b0 0x622fc0 0x61733c 0x622eaf 0x7f78cd 0x7401a6 0x73ecbf 0x73ebd9 0x73de34 0x73dc6e 0x73ea29 0x741922 0x7ebfec 0x738bc4 0x738dbf 0x738f55 0x741f67 0x705fcc 0x706fab 0x718315 0x71924b 0x70acf8 0x27e8df9 0x27e8ad0 0x1910bf5 0x1910962 0x1941bb6 0x1940f44 0x1940e1b 0x7067da 0x70865c 0x6d5d 0x2395)
libc++abi.dylib: terminate called throwing an exception
I had the same exception when I was trying to set the table header view.
When I noticed that the view had Contraints I just unchecked the "Use Autolayout" option from Storyboard.
Screenshot: http://i.stack.imgur.com/5jWHy.png
This solved for me.
The best way to overcome this is to use Interface Builder to setup the UITableView header, then add an Outlet to the height NSLayoutConstraint.
Try this:
logoImageView.translatesAutoresizingMaskIntoConstraints = YES;
(If not works, try to remove:
tableHeaderView.translatesAutoresizingMaskIntoConstraints = NO; //Remove this line
:)
I didn't get any proper solution for this issue but you can fix it by using frames and not setting translatesAutoresizingMaskIntoConstraints property to No (by default its yes, so don't set it)
CGRect headerViewFrame = CGRectMake(0,0,320,60); //Frame for your header/footer view
UIView *tableHeaderView = [[UIView alloc] initWithFrame:headerViewFrame];
tableHeaderView.translatesAutoresizingMaskIntoConstraints = Yes; //Or don't set it at all
[self.tableView setTableHeaderView:tableHeaderView];
I am using ABNewPersonViewController to add new contact to the address book. Every thing is fine if I do not add any photo from photo albums. It crashes if I add any photo and here is the log:-
NSInvalidArgumentException', reason: '*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: UIImagePickerControllerOriginalImage)
What I am doing wrong, or how I can fix this problem
Thanks
This is the code I use:
mNewPersonViewController = [[[ABNewPersonViewController alloc]init]autorelease];
mNewPersonViewController.hidesBottomBarWhenPushed = YES;
mNewPersonViewController.addressBook = app.addressBook;
mNewPersonViewController.newPersonViewDelegate = self;
UINavigationController *presonNavController = [[UINavigationController alloc]initWithRootViewController:mNewPersonViewController];
self.mPopOverController = [[UIPopoverController alloc]initWithContentViewController:presonNavController ];
CGRect frame = [sender frame];
[self.mPopOverController presentPopoverFromRect:frame inView:self.view permittedArrowDirections: UIPopoverArrowDirectionUp animated:YES];
[presonNavController release];
Looks like you are trying to insert a nil value into the dictionary.