Using UIButton currentTitle to create an action

Discussion in 'iOS Programming' started by ledzepster, Jun 2, 2010.

  1. ledzepster macrumors newbie

    Jun 2, 2010

    I've spent hours looking for an answer to what I know is a newbee question but to no avail. I know the solution has to be straightforward but....

    I want to use the title from a button to perform a task. What I have is the following:

    -(IBAction)doSomethingWithButton: (id)sender {

    NSString *whatToDo = [(UIButton *)sender currentTitle];
    if (whatToDo == @"+")
    {//do some action
    [whatToDo release];

    The problem is that the logical operator doesn't work. It seems that whatToDo is type NSString and is incompatible with @"+".

    Any help appreciated!

  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    You cannot compare two NSStrings with ==. In fact, in general, you cannot do that with two objects: you are comparing the addresses of the pointers. Not the content of the two objects.

    Is isEqualToString:
  3. admanimal macrumors 68040

    Apr 22, 2005
    Also, you should not be releasing whatToDo because you don't create or retain it.
  4. ledzepster thread starter macrumors newbie

    Jun 2, 2010

    thanks to both of you.obviously a fundamental flaw in my thinking - I'm from a cobol / .net background. Cheers

Share This Page