value adding to the UITextField - uitextfield

I am trying to display a UITextField based on the OK button on the alert windows. So, when the user presses the OK button, then another textbox should come where the user can enter profile name. However, based on the code below, I see that immediately after OK is clicked, it goes on saying, that "No profile name specified" as it finds the profile.txt as empty. Here is piece of code, which displays the popup alert, prompting the user to save a profile with profile name.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hello, User ! Save Profile" message:#"Provide a profile Name" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK" ,nil];
profileName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 2600.0, 25.0)];
[profileName setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:profileName];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
[alert setTransform:myTransform];
[alert show];
[alert release];
Appreciate your response !
Thanks in advance !

I was able to get it working for iOS7 with,
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
profileName = [alert textFieldAtIndex:0];
Thanks

Related

How to display dialog box in OS X using Finder Sync Extension and Objective-C

I am creating a cocoa application with finder sync extension. I'm trying to open dialog box on some events of finder app.I am beginner for x code and objective c. I have tried the below code on some event..
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:#"OK"];
[alert addButtonWithTitle:#"Cancel"];
[alert addButtonWithTitle:#"OK"];
[alert addButtonWithTitle:#"Cancel"];
[alert setMessageText:#"Delete the record?"];
[alert setInformativeText:#"Deleted records cannot be restored."];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] == NSAlertFirstButtonReturn) {
// OK clicked, delete the record
}
But this code is just for presenting alert box.
Can anyone suggest me how do I get dialog box.
Try UIAlertView and UIAlertController or else simply use NSAppleScript

UIAlertView crash iOS7 - Assertion failure

I have a problem regarding the UIAlertView on iOS7.
When I launch my application, it crashes with the following message:
*** Assertion failure in -[UIKeyboardTaskQueue performTask:], /SourceCache/UIKit_Sim/UIKit-2903.2/Keyboard/UIKeyboardTaskQueue.m:388
The error occurs on the following line:
- (IBAction)updatePositions:(id)sender{
_alert = [[UIAlertView alloc] initWithTitle:#"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[_alert show]; <====== IT CRASHS HERE
[NSThread detachNewThreadSelector:#selector(updateDataThread) toTarget:self withObject:nil];
}
I'm using ARC and the property _alert is set defined as: #property (nonatomic,strong)
This error seems strange, because on iOS6 the code works perfectly and I don't know what should be different on iOS7.
Does anyone have an idea what could the error?
Thanks in advance.
I encountered the same error, and the issue was that the UIAlertView was attempting to be shown from a thread which wasn't the main thread.
The crash however wouldn't always occur, only when a first AlertView was already being shown while this second AlertView was trying to pop up as well.
In my case, a simple fix was to do:
//Your code here
...
//Alert
_alert = [[UIAlertView alloc] initWithTitle:#"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
dispatch_async(dispatch_get_main_queue(), ^{
//Show alert here
[_alert show];
});
//Resume your code here
...
I just had this problem after forgetting that I was working from a background thread. I don't know if that's the case here, but I'd make sure you're not trying to call updatePositions: from anything other than the main thread.
Change your code like this :
_alert = [[UIAlertView alloc] initWithTitle:#"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[_alert show];
removing [[ and ]] around #"text"
But, your I don't think your problem came from this UIAlertView.
I had the same problem as well but not too familiar with the method dispatch_async. I used
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:NO];
and the problem hasn't come up again.
Put your alertview code in a separate function like
-(void)showAlert
{
_alert = [[UIAlertView alloc] initWithTitle:#"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[_alert show];
}
Then in your IBAction do this
- (IBAction)updatePositions:(id)sender
{
[self performSelectorOnMainThread:#selector(showAlert) withObject:nil waitUntilDone:YES];
[NSThread detachNewThreadSelector:#selector(updateDataThread) toTarget:self withObject:nil];
}
You can also do like this:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Your title" message:#"Your message" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:YES];
However, if you need to show the same alert in multiple places it's better to create a separate function for it.

Pop-up message on macOS programming

Like using UIAlertView on iOS. There should be a similar solution for creating a pop-up message on macOS. Tried to search but could not find anything useful.
The class you're looking for is NSAlert. Information on this class can be found in its class reference here. And here is an example of its usage:
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:#"Some awesome message text"];
[alert addButtonWithTitle:#"OK"];
[alert runModal];

Usernotes in ios

I want to create a user note form in my application,currently am using one textview inside a view its looking bad !! is there any other control suits for this purpose? Main aim is when user click the button a small textview will appear they can add comments there and save it into plist.
I want something like this(check the image)
i want that kind of usernotes (its my image) please give me some advices and helps to develop this..
Using UIAlertView with UITextView can be useful for you.
Implement UIAlertViewDelegate in .h file.
UITextView *comments;
-(IBAction)btnAddClicked:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Noreply Email" message:#"\n\n\n\n\n" delegate:self cancelButtonTitle:#"Close" otherButtonTitles:#"Send", nil];
comments = [[UITextView alloc] initWithFrame:CGRectMake(15,45, 255, 100)];
[comments setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"mailbody.png"]]];
[comments setFont:[UIFont fontWithName:#"Helvetica" size:15]];
comments.scrollEnabled = YES;
[comments becomeFirstResponder];
[alert addSubview:comments];
[alert show];
[alert release];
}
Here alert will be prompted with small textview you can add comments and then handle text inside delegate method like this.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==1) //Send button pressed
{
//handle your comment here
NSLog(#"%#",comments.text);
}
}

UIAlertview is called multiple times

I have the following code in my application. On a view controller I have two UIButton controls that each do different operations. When I press the first button I have a UIAlertView to confirm the operation. This works fine. I setup the second button the same way. When I press the second button the first UIAlertView appears briefly, and then the second UIAlertView appears. It works okay at that point but then the first UIAlertView appears again.
If I take out the UIAlertViews completely and just update a label on the view to indicate which button was pressed I don't get either button called a second time so I have isolated this to the inclusion of the UIAlertViews.
Can anyone point to something in my code that is causing this? Here's the code.
- (IBAction)clearInspectionsClicked {
UIAlertView *alertClear = [[UIAlertView alloc] initWithTitle:#"Please Confirm"
message:#"Clear out all inspection data?"
delegate:self
cancelButtonTitle:#"Clear"
otherButtonTitles:#"Cancel", nil];
[alertClear show];
}
- (IBAction)loadSampleDataClicked {
UIAlertView *alertLoad = [[UIAlertView alloc] initWithTitle:#"Please Confirm"
message:#"Load Sample data?"
delegate:self
cancelButtonTitle:#"Load"
otherButtonTitles:#"Cancel", nil];
[alertLoad show];
}
-(void) alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:#"Clear"])
{
[self clearInspections];
[self.StatusLabel setText:#"Inspection data has been cleared!"];
}
if ([title isEqualToString:#"Load"])
{
[self loadSampleData];
[self.StatusLabel setText:#"Sample data has been loaded!"];
}
}
Is it possible that you have one of the buttons wired to two of those actions? it is possible to wire multiple actions to one given control in Interface Builder, and it would cause this exact behavior.

Resources