mystr appendString: sender

Discussion in 'iOS Programming' started by FreedomApple, Oct 2, 2011.

  1. FreedomApple, Oct 2, 2011
    Last edited by a moderator: Oct 2, 2011

    FreedomApple macrumors newbie

    Joined:
    Oct 2, 2011
    #1
    Hello,
    I'm very new to Objective C. I'm trying to figure out why when I press my UIButton it crashes when sender is in appendString: sender. Am I missing something?
    If I change sender to a string @"World!" it works fine.


    Code:
    - (IBAction) search:(id)sender{
        NSMutableString* mystr = [NSMutableString stringWithString: @"Hello"];
        [mystr appendString: sender];
    }

    Thank You
     
  2. FreedomApple, Oct 2, 2011
    Last edited by a moderator: Oct 2, 2011

    FreedomApple thread starter macrumors newbie

    Joined:
    Oct 2, 2011
    #2
    this also doesn't work.

    Code:
    -(IBAction)linkButtonClick:(id)sender {
    NSString* launchUrl = sender;
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
    }
     
  3. lefooey macrumors member

    Joined:
    Dec 26, 2009
    Location:
    Spokane, WA
    #3
    Code:
    - (IBAction) search:(id)sender{
        NSMutableString* mystr = [NSMutableString stringWithString: @"Hello"];
        [mystr appendString: sender];
    }
    sender is probably your UIButton, so it's not valid to pass as an NSString reference to NSMutableString appendString:

    Perhaps you were looking for sender.title.text?
     
  4. FreedomApple thread starter macrumors newbie

    Joined:
    Oct 2, 2011
    #4
    Thanks for the Reply.
    What I read is that the sender is a ID not a string.

    Here is what I ended up having to do.

    Code:
    NSString *title = [(UIButton *)sender currentTitle];
    works now.
     

Share This Page