UIAlertView Messages - iphone

Trying to include a instance variable in a message that a UIAlertView Shows.
lostAlert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:(#"You Were Wrong, the correct structure was %#", structureName) delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
however, when the Alert is shown, no message is shown.
Any ideas and help would be appreciated :)
Sam

did you try it with:
[NSString stringWithFormat:#"You Were Wrong, the correct structure was %#", structureName]
instead of
(#"You Were Wrong, the correct structure was %#", structureName)

Related

UIAlertView message

I'm having problem with my UIAlertView, Here is how I show it,
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"エラー"
message:#"Oneスロットに何も画像が設定されていません"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
But then the preview looks like this:
What I wanted is to make it just 1 Line, but I have read in some thread/question that it shouldn't be done, what is the best way to do this without making my app being rejected? I Have read about changing its width, but is this allowed?

didFailToRegisterForRemoteNotificationsWithError is fired, how to get more info?

For the first time I am playing with APNS, I tried to run a proof of concept, with an iOS 5.0.1 device, and the didFailToRegisterForRemoteNotificationsWithError is fired. I know it has been fired because I show an UIAlertView to notify the error:
- (void)application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
// Inform the user that registration failed
NSString* failureMessage = #"There was an error while trying to \
register for push notifications.";
UIAlertView* failureAlert = [[UIAlertView alloc] initWithTitle:#"Error"
message:failureMessage
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
How can I get more info about the error?
Try doing something like NSLog(#"%#", error.userInfo");, that should output some info into the terminal.
I ended up with this code, which works and lets me progress a bit:
NSString* failureMessage = error.localizedDescription;
UIAlertView* failureAlert = [[UIAlertView alloc] initWithTitle:#"Error"
message:failureMessage
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[failureAlert show];
Sorry, iObjectiveC noob here.

Can't figure out an error with stringWithFormat

I'm having a really basic problem with NSString stringWithFormat. I want to take the name that the user enters and display in an alertView: Welcome username.
NSString *welcomeMessage = [NSString stringWithFormat:(#"Welcome %#", passedData)];
UIAlertView *alert = [[UIAlertView alloc] //show alert box with option to play or exit
initWithTitle: welcomeMessage
message:#"Once you press \"Play\" the timer will start. Good luck!"
delegate:self
cancelButtonTitle:#"I want out!"
otherButtonTitles:#"Play",nil];
[alert show];
passedData is the username that has been entered. The way I have it at the moment - only the username is being displayed in the title of the alert box, and not the "Welcome" part. I know i'm missing some really basic knowledge here but would appreciate some help.
I think that () are not needed. Try using that:
NSString *welcomeMessage = [NSString stringWithFormat:#"Welcome %#", passedData];
instead of
NSString *welcomeMessage = [NSString stringWithFormat:(#"Welcome %#", passedData)];
Hope it helps

iPhone: UIAlertView overlap

Every 10 min I synchronize my app with server, and when something wrong with server, I show UIAlertView.
NSString *alertTitle = #"Sync failed";
NSString *alertMessage = #"Something wrong with server"
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:alertTitle
message:alertMessage
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", #"OK button title")
otherButtonTitles:nil];
[alertView show];
[alertView release];
If to shoot down server and do not touch phone, in hour there will be 6 Alert Dialogs, and I supposed to close 6 AlertDialogs. How to fix that ? Can AlertView check if its already shown to user or something like that ? Thanks...

iPhone: Using Alerts to Help Debugging

I've been building a rather complex system and there's come the time now where I want more concise debugging. I would like to display the contents of a variable (for this example an NSString called v_string) in a notification window (the kind of window that appear when you receive an SMS text).
Is there an easy way to just call an alert with a variable?
Thanks in Advance,
Dan
NSLog does not do? If not (like if you need to debug an application running on a disconnected device), you can extend the UIAlertView with a category:
#implementation UIAlertView (Logging)
+ (void) log: (id <NSObject>) anObject
{
NSString *message = [anObject description];
UIAlertView *alert = [[self alloc] initWith…];
[alert show];
[alert release];
}
And then in code:
NSString *anInterestingString = …;
[UIAlertView log:anInterestingString];
When you build the string to display in the alert window, simply append your variable's string represenation using stringByAppendingString.
Alert window is cumbersome. Use NSLog instead:
NSLog(#"Variable is: %#", v_string);
And in Xcode's console you will see that text.
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"My Debug String" message:v_string delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[message show];
[message release];
I think this way you can see what you want.
But, as zoul said, why not to use NSLog(#"my var: %#", v_string); ?
Hope that it helps.