Reputation: 690
I can't figure out why this won't work, I've tried it 100 ways. The AlertView shows up with a blank message. Here's my code:
eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
timeTillRest is an NSString. and just before calling the alertview an NSLog(@"%@",timeTillRest);
displays the string without trouble.
Upvotes: 1
Views: 1786
Reputation: 1037
Why would you use an alertview as an instance variable? There's no need for that. It's just as easy as this:
UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[eventChoiceNow show];
[eventChoiceNow release];
Upvotes: 2
Reputation: 14427
This should work just fine. Testing using this code:
NSString *timeTillRest = @"Testing";
UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[eventChoiceNow show];
And it works fine. Also testing using:
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong) NSString *timeTillRest;
@end
@implementation ViewController
@synthesize timeTillRest;
- (void)viewDidLoad
{
[super viewDidLoad];
timeTillRest = @"Testing";
UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:@"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[eventChoiceNow show];
// Do any additional setup after loading the view, typically from a nib.
}
And that works flawlessly too. Make sure you aren't setting that property to nil anywhere.
Upvotes: 2