Saturday 9 April 2011

Error message: unrecognized selector sent to class when calling a category method defined in a static class

I was getting the following error message "unrecognized selector sent to class" from the following block of code i an iPad application i am writing.

[NSNumber parseString:(NSString *)contentLength intoUInt64:&requestContentLength]

parseString is a category which had been added to the NSNumber class and was defined in a header file correctly like so...

+ (BOOL)parseString:(NSString *)str intoUInt64:(UInt64 *)pNum
{
 if(str == nil)
 {
  *pNum = 0;
  return NO;
 }
 
 errno = 0;
 
 // On both 32-bit and 64-bit machines, unsigned long long = 64 bit
 
 *pNum = strtoull([str UTF8String], NULL, 10);
 
 if(errno != 0)
  return NO;
 else
  return YES;
}

Now all worked fine if i used this directly in my application however when this code was part of a linked static library the code would fail with the error message.

After a little surfing i found that you need to add -all_load into the liker options for the main application.

According to the post below -ObjC should also work in XCode4 but I have not been able to get this to work only -all_load

http://stackoverflow.com/questions/932856/calling-method-on-category-included-from-iphone-static-library-causes-nsinvalidar

Friday 8 April 2011

How to Hide a Toolbar on iOS Devices

// in a UIViewController subclass
- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setToolbarHidden:NO animated:YES];
    [super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setToolbarHidden:YES animated:YES];
    [super viewWillDisappear:animated];
}