I'm trying to create a text box with multiple fields, but I'm having trouble getting the second to show (as a matter of fact, when I type the second field in, it causes my text box not to show up all together.)
Here's what I have:
-(IBAction)popupCheckIn {
//UIAlertView *alertCheckIn = [[UIAlertView alloc] initWithTitle:#"Check in" message:#"Please fill out the following to check in." delegate:self cancelButtonTitle:#"Check in." otherButtonTitles:#"Cancel.", nil];
//[alertCheckIn show];
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"Check in" message:#"Please fill out the following fields to check in." delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * nameField = [alert textFieldAtIndex:0];
nameField.keyboardType = UIKeyboardTypeDefault;
nameField.placeholder = #"Your Name";
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * hostField = [alert textFieldAtIndex:1];
hostField.keyboardType = UIKeyboardTypeDefault;
hostField.placeholder = #"Host Name";
[alert addButtonWithTitle:#"Check in."];
[alert show];
When I run this code, I get an error that says "Thread 1: signal SIGABRT" and my pop up won't come up at all; when I have just the name field, it works fine.
What am I doing wrong with my second text field? Thanks!
I think that your error arises because that type of UIAlertView doesn't contain more than one UITextField, and when trying to access the second it raises a NSRangeException. This is according to the docs.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html#//apple_ref/occ/instm/UIAlertView/textFieldAtIndex:
I tried your code, the entire error message is:
2014-06-26 17:13:56.213 Testing1[2444:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'textFieldIndex (1) is outside of the bounds of the array of text fields'
The issue, is that you only have ONE UITextField with the UIAlertViewStyle set to UIAlertViewStylePlainTextInput. So this part of code ([alert textFieldAtIndex:1] is causing the crash).
Repeating the line alert.alertViewStyle = UIAlertViewStylePlainTextInput; won't create a new one.
The only way to get 2 UITextFields, is to use the UIAlertViewStyleLoginAndPasswordInput UIAlertViewStyle.
A way could be then to set the second one (like the first one) is like this:
[hostField setSecureTextEntry:FALSE];
But personally, I think that I don't recommend it. It may be blocked in the future.
Since we cannot custom really the existing UIAlertView since iOS7 (can't add subview), I'd suggest you create (or find in CocoaControls/GitHub) your own CustomAlertView-like.
You'll want to use alert with the alert style UIAlertViewStyleLoginAndPasswordInput. See this answer: UIAlertView with Two TextFields and Two Buttons
Related
In my app I am using a button to print a tableview of information to a printer. I am using the simple code below to print. I get output fine and even in duplex mode. I use the exact output table for a variety of reports. My problem - How do I include a title and the column headers?
(IBAction)btnPrintTable:(id)sender {
NSPrintOperation *op;
op = [NSPrintOperation printOperationWithView:rptTable];
if (op)
[op runOperation];
else{
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:#"Cancel"];
[alert setMessageText:#"No Table Data available for printing"];
[alert setInformativeText:#"Cancel and create table data"];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] == NSAlertFirstButtonReturn){}
}
}
There are 6 column headers: Number: Extension: Year: Type: Price: Description:
I have read 'About MAC Printing' and 'Printing Programming Topics for Cocoa'. I can not reference a table header/column design detail. I can not find anything in pagination topics referencing this issue. Can anyone help?
Here is my code that calls "displayAlert". The problem is not only do I get an error message (wait_fences: failed to receive reply: 10004003) but the "alert" is displayed twice!
if(gSiteID.globalSiteID.length == 0) { // user didn't choose site
[self displayAlert:NSLocalizedString(#"Missing Site ID", nil) andData:NSLocalizedString(#"You must choose a site from the View Sites page",nil)];
return;
}
This the code for "displayAlert":
- (void) displayAlert: (NSString *) title andData: (NSString *) errorMsg {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: title
message: errorMsg
delegate:nil
cancelButtonTitle: #"OK"
otherButtonTitles: nil];
[alert show];
return;
}
I have searched SO and Google and found nothing that is specific to my issue. What am I doing wrong?
Are you testing this on a real device or the simulator? wait_fences: failed to receive reply usually means something bad happened with the debugger's connection to your device, or that you sat at a breakpoint for a really long time and it timed out. Are you sure that the code only executes once, and that nothing else could call that method? Stick breakpoints in your if statement and in your displayAlert:andData: method and see what happens. Run through your logic and find all the cases when that display alert method can be called and stick breakpoints on all of them.
I found the problem: indeed I was calling it twice from different .cs files (do you see the egg on my face?). Jack Lawrence please post your answer to the question, since you hit it on the head.
A noob question.
I have an alert:
"alertMessage" = "This is my message: 1 2 3. And another one: 5 6 7";
which I am displaying with:
NSString *asd = NSLocalizedString (#"alertMessage", #"");
NSString *alertTitle = NSLocalizedString (#"alertTitle", #"");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle message:asd delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
How do I implement line breaks so "And Another one:" starts on the second line.
thank you!
Add line break characters (\n) to your message.
Add a \n in your string literal.
More details here
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"Some failure message"
delegate:self
cancelButtonTitle:#"cancel"
otherButtonTitles:#"retry", nil
];
[alert show];
[alert release];
I got two warnings pointing at this block of code.
Unused variable 'alert'
Missing sentinel in function call
My code looks similar to all the examples online. Why is it broken?
This code works fine for me. Try cleaning all targets and building again to see if the error persists.
Because you call [alert show], you should not get an unused variable warning on alert.
Since you include nil after otherButtonTitles, you should not get a missing sentinel warning.
I want to replace the title and message with the return values from a different class and also put it into an if statement that will see if the return value matches a value i state. can you help me out a little bit, this is my code below, I'm using theos by the way
the 3 methods i want to get the values for are
-(id)title
-(id)message
-(id)_appName
from the SBBulletinBannerItem class
any help is appreciated
%hook SBBulletinBannerController
- (void)_handleBannerTapGesture:(id)reply
{
reply = [[UIAlertView alloc] initWithTitle:#"title" message:#"message" delegate:self cancelButtonTitle:#"Close" otherButtonTitles:#"Reply", nil];
[reply show];
[reply release];
}
%end
It sounds like you'll want to use delegates and protocols. You may have seen this using standard Cocoa and Cocoa Touch classes. This is how you respond to events in a UITableView.
You can find examples of implementing this yourself here.