Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

FreedomApple

macrumors newbie
Original poster
Oct 2, 2011
5
0
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
 
Last edited by a moderator:
this also doesn't work.

Code:
-(IBAction)linkButtonClick:(id)sender {
NSString* launchUrl = sender;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
}
 
Last edited by a moderator:
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?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.