views:

259

answers:

2

Hi All,

I am having an issue in iphone when i want to use a custom button in the keypad(text field filler) of my application page. i have embedded a button named dot in the keypad and it is appearing fine but when i click it, it is supposed to go to an action which i defined. but it crashes.

- (void)sendDecimal:(id)sender {
    // Post a Notification that the Decimal Key was Pressed.
    [[NSNotificationCenter defaultCenter] postNotificationName:@"DecimalPressed" object:nil];   
}

it runs till the application tries to send notification to i dont know may be the routine or function or method.

Can somebody help me in this regards.

thanks

EDIT

Here is the error message:

-[UITableView addDecimal:]: unrecognized selector sent to instance 0x4051e00 
2010-03-26 16:08:42.272 app[2855:20b]

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UITableView addDecimal:]: unrecognized selector sent to instance
0x4051e00' 

EDIT

i have defined the addDecimal selector, here is the code......

- (void)viewDidAppear:(BOOL)animated    {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:tableView selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];

Edit

Yes i have written this as [dot addTarget:self action:@selector(sendDecimal:) forControlEvents:UIControlEventTouchUpInside];

+1  A: 

have you written something like

[YourButtonButton addTarget:self action:@selector(addDecimal:) forControlEvents:UIControlEventTouchUpInside];

Then replace it with

[YourButtonButton addTarget:self action:@selector(sendDecimal:) forControlEvents:UIControlEventTouchUpInside];

from your comment i am guessint it's just spelling mistake or something

mihirpmehta
actually i have taken the source code from an example of how to create a custom button and it works fine there as they are defining it in the main application delegate file but i have an application and i have to do is on viewControllers. so i am combining those so that i dont have to change anything in the main delegate files of application. i hope i am a little bit clear, sorry if still not :(
Ch Sab
A: 

Problem Solved Guys

Error

[[NSNotificationCenter defaultCenter] addObserver:tableView selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];

Resolve:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];

Put addObserver to self rather than tableview

Ch Sab