#import "InterfaceFunctions.h"
@implementation InterfaceFunctions
/*
* Creates a Round Rect Button that is inserted in the view
*/
+ (void)createNormalButton: (UIButton *) bMyButton
atPosX: (double) X
atPosY: (double) Y
withSizeY: (double) HEIGHT
withSizeX: (double) WIDTH
withColor: (UIColor *) cMyColor
withTag:(int) iTag
withTitle: (NSString *) sTitle
inView: (UIView *) Vista {
NSLog(@"Executing createNormalButton...");
bMyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //The button is allocated
[bMyButton setFrame:CGRectMake(X, Y, WIDTH, HEIGHT)]; //The type and size of the button is setted
[bMyButton setTitle: sTitle forState:UIControlStateNormal]; //The button's title is setted
[bMyButton setTitleShadowColor:cMyColor forState:UIControlStateNormal]; //The button's title shadow color is setted for its normal state
[bMyButton setBackgroundColor: cMyColor]; //The button's background color is setted
[bMyButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; //The button's title color is setted for its normal state
[bMyButton setTag: iTag]; //The button's tag is setted in order to select the proper the action
[Vista addSubview:bMyButton]; //The button is added to the view
}
And I call the createNormalButton 'function' like this:
Code:
#import "Main.h"
#import "InterfaceFunctions.h"
@implementation Main
(...)
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.view = [[UIView alloc] initWithFrame: CGRectMake(0.0, 0.0, SCREEN_WIDTH, SCREEN_HEIGTH)]; //The visual view is created. In this view all the objects will be added
[self.view setBackgroundColor:[UIColor blackColor]]; //Background color is setted for the main view
NSLog(@"Main viewDidLoad executing...");
//InterfaceFunctions * intFunc = [[InterfaceFunctions alloc] init];
//The main 4 buttons are created
[InterfaceFunctions createNormalButton: bConnect atPosX: CENTER_POS_X atPosY: CENTER_POS_Y withSizeY: NORMAL_BUTTON_HEIGHT withSizeX: NORMAL_BUTTON_WIDTH withColor: [UIColor blackColor] withTag: 1 withTitle: @"Connect" withView: self ];
[InterfaceFunctions createNormalButton: bConnect atPosX: CENTER_POS_X atPosY: CENTER_POS_Y + 60 withSizeY: NORMAL_BUTTON_HEIGHT withSizeX: NORMAL_BUTTON_WIDTH withColor: [UIColor blackColor] withTag: 1 withTitle: @"Disconnect" withView: self ];
[InterfaceFunctions createNormalButton: bConnect atPosX: CENTER_POS_X atPosY: CENTER_POS_Y + 60*2 withSizeY: NORMAL_BUTTON_HEIGHT withSizeX: NORMAL_BUTTON_WIDTH withColor: [UIColor blackColor] withTag: 1 withTitle: @"Settings" withView: self ];
[InterfaceFunctions createNormalButton: bConnect atPosX: CENTER_POS_X atPosY: CENTER_POS_Y + 60*3 withSizeY: NORMAL_BUTTON_HEIGHT withSizeX: NORMAL_BUTTON_WIDTH withColor: [UIColor blackColor] withTag: 1 withTitle: @"Exit" withView: self ];
}
My main class inherits from UIViewController and the InterfaceFunctions class from NSObject.
I've also tried to import Foundation/Foundation.h in the two class and it also crashed, equal than when I try to put @class InterfaceFunctions in the Main class.
The exception message is the giveaway - unrecognized selector.
Usually means typo, case error, something like that. In your particular case, the last argument is supposed to be "inView" and you are sending "withView".
I've changed that, now is all 'inView' and, now, the problem is here:
Code:
[Vista addSubview:bMyButton]; //The button is added to the view
And the log says:
Code:
[Main addSubview:]: unrecognized selector sent to instance 0x4d10ad0
Isn't correct the addSubview?
Thanks for the answer.
I'm going to guess that Main is a UIViewController? You'd want the view property of Main, not Main itself.
Aren't you getting all kinds of compiler warnings? Saying things like "... may not respond to ..."? You can solve these problems long before you try running the program.
You are completly right! In fact, the Main class is an UIViewController, and yes, I had those warnings, but I thought that they mean that the Main class didn't have access to the methods, because of their visibility or something.
Well, thanks a lot. For your speed and effectiveness answering and guessing