Problem with NSStrings and UIAlertView <p>I have having a very odd issue when utilizing this UIAlertView. When viewing a Physician they have several offices. Upon selecting one you get an alert that offers to call this location or display it on a map. To create the alert and to have data at the ready when the alert is dismissed, I declared 4 NSStrings (although I probably only need 2) in the header file. (alertTitle, alertText, alertNumber, and alertAddress) </p> <p>When looking at the code, the problem is where the alertAddress is involved. Also keep alertNumber in mind. I had a lot of this code condensed but have expanded it to help myself find the problem!</p> <pre><code> -(IBAction)address1ButtonPressed:(id) sender { Formatter *pnf = [Formatter alloc]; alertTitle = [physician objectForKey:ADDRESS1DESC_KEY]; NSString *a = [physician objectForKey:ADDRESS1A_KEY]; NSString *b =[physician objectForKey:ADDRESS1CITY_KEY]; NSString *c =[physician objectForKey:ADDRESS1STATE_KEY]; NSString *d = [physician objectForKey:ADDRESS1ZIP_KEY]; NSString *p = [physician objectForKey:PHONE1A_KEY]; alertAddress = [[NSString stringWithFormat:@"http://maps.google.com/maps?q=%@,+%@,+%@+%@",a,b,c,d] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%@",alertAddress); alertText = [NSString stringWithFormat:@"%@\n%@, %@ %@\n%@",a,b,c,d,[pnf stringFromPhoneNumber:p]]; alertNumber = [p stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; [pnf release]; UIAlertView *phoneAlert = [[UIAlertView alloc] initWithTitle:alertTitle message:alertText delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call",@"View Map",nil]; [phoneAlert show]; } </code></pre> <p>All is well until we reach the point where we handle the alert dismissal. alertNumber seems to come across just fine, I can use it to trigger the phone call and Log it to the console. </p> <p>alertAddress however is not at all happy about doing the same thing. even trying to Log it to the Console causes a EXC_BAD_ACCESS. alertAddress logs the data correctly before the alert is involved but accessing this data at all when handling the alert button dismissal causes a problem. I have even used the alertNumber it is place and the code functions perfectly. </p> <p>Why are both exact same NSString variables behaving so differently when used the exact same way?</p> <pre><code>- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { NSLog(@"Dialing: %@",alertNumber); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",alertNumber]]]; } if (buttonIndex == 2) { NSLog(@"Map Selected"); NSLog(@"alertAddress contains: %@",alertAddress); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",alertAddress]]]; } } </code></pre> <p>Here are the related declarations in the header file too...</p> <pre><code>@interface PhysicianDetailViewController: UIViewController { ... NSString *alertTitle; NSString *alertText; NSString *alertNumber; NSString *alertAddress; ... } @property (nonatomic, retain) NSString *alertTitle; @property (nonatomic, retain) NSString *alertText; @property (nonatomic, retain) NSString *alertNumber; @property (nonatomic, retain) NSString *alertAddress; ... </code></pre> <p>And here is the console output during this process if it helps....</p> <pre><code> &gt; 2010-10-29 11:09:17.954 [2672:307] http://maps.google.com/maps?q=123%20Main%20Street%0ASuite%20A,+Tampa,+FL+11111 &gt; 2010-10-29 11:09:21.657 [2672:307] Map Selected &gt; Program received signal: “EXC_BAD_ACCESS”. &gt; kill quit </code></pre>