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);
}
}
Related
I had used an instance of SDCAlertView in my project to add a UITextView inside an alert to do some facebook posts.It doesnt seem to work properly anymore on ios8.
I had used the following code.
SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:#"Post To Facebook"
message:#""
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Post", nil];
UITextView *textView = [[UITextView alloc] init];
[textView setTranslatesAutoresizingMaskIntoConstraints:NO];
[textView setEditable:YES];
textView.autocorrectionType = UITextAutocorrectionTypeNo;
[alert.contentView addSubview:textView];
[textView sdc_pinWidthToWidthOfView:alert.contentView offset:-5];
[textView sdc_pinHeight:120];
[textView sdc_horizontallyCenterInSuperview];
[textView sdc_verticallyCenterInSuperviewWithOffset:SDCAutoLayoutStandardSiblingDistance];
[alert showWithDismissHandler: ^(NSInteger buttonIndex) {
NSLog(#"Tapped button: %#", #(buttonIndex));
if (buttonIndex == 1) {
NSLog(#"POST %#", textView.text);
}
else {
NSLog(#"Cancelled");
}
}];
Result on iOS 7
Result on iOS 8 GM
Please let me know if I can fix this issue with some change in my code.
I managed to fix this problem by replacing following line
[textView sdc_verticallyCenterInSuperviewWithOffset:SDCAutoLayoutStandardSiblingDistance];
with the following:
[alert.contentView sdc_pinHeight:120 + SDCAutoLayoutStandardSiblingDistance];
[textView sdc_alignEdgesWithSuperview:UIRectEdgeTop insets:UIEdgeInsetsMake(SDCAutoLayoutStandardSiblingDistance, 0, 0, 0)];
If anyone wants to refer more about this discussion, please visit the following link
https://github.com/sberrevoets/SDCAlertView/issues/49
I have a NSAlert in XCode5
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:#"Notificación"];
[alert setInformativeText:mensaje];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert beginSheetModalForWindow:window modalDelegate:nil
didEndSelector:#selector(myMethod})
contextInfo:nil];
as you see on didEndSelector I have a section for adding a method, is it possible to create there inside a custom method for making just an action, for instance something like this
[alert beginSheetModalForWindow:window modalDelegate:nil
didEndSelector:#selector(myCustomMethod{NSLog(#"hola");})
contextInfo:nil];
this is for saving the time of adding tons of methods one for each NSAlert
thanks in advance for the support
create separated method with some NSLOG for example
- (void)logs {
NSLog(#"lalalalalal")
}
Then send it to selector:
#selector(logs)
If your method receiving some variable, your select should be like:
#selector(logs:)
I am trying to set up an alert view so that when the "Ok" button is pressed, an action sheet comes up with two options. I believe i have it in the right format and there are no errors, but when I run it, nothing happens. please help and thank you in advanced.
-(IBAction)sendSG:(id)sender{
UIAlertView *message = [[UIAlertView alloc]
initWithTitle:#"Send Study Guides!"
message:#"Please send your study guides to help create a bigger and more efficent network of study guides. You can send them by email, or you can take a picture of your study guide and send it to us."
delegate:self //Changed Here
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
[message show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
UIActionSheet *sendOptions = [[UIActionSheet alloc]
initWithTitle:#"Add study guide"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Destructive Button"
otherButtonTitles:#"Email", #"Take a picture", nil];
[sendOptions showInView:self.view];
}
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSString *emailTitle = #"Study Guides";
NSArray *toRecipents = [NSArray arrayWithObject:#"blank#gmail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
[mc setSubject:emailTitle];
[mc setToRecipients:toRecipents];
[self presentViewController:mc animated:YES completion:NULL];
}
}
set Delegate of your alert view to self.
In your code,
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
is not being called due to this
Yes, and change your button index too… forgot to tell you that. it should be 1 for both alertView & actionSheet.
Make your viewController ActionSheet Delegate. add "UIActionSheetDelegate" in your viewController.h
#interface XYZViewController : UIViewController UIActionSheetDelegate (enclose in angular braces)
Everything Else will work fine.. Let me know if there is any issue
You got the wrong button index.
The button buttonIndex == 0 is the cancel button,buttonIndex == 1 is the ok button.
Try this in alert view's callback:
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// show action sheet here.
});
If it works for you, modify the delayInSeconds as you wish.
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.
I was using UIImagePickerController without any problem.
Before when I was taking a picture in the landscape mode, the picture in the Preview (when the buttons Retake and Use Photo were present) was always automatically rotated so as to appear correctly in the portrait mode.
But now when I use the UIImagePickerController the preview mode does not rotate the picture anymore.
Where can I activate or desactivate this mode?
Here is my code:
- (IBAction)getCameraPicture{
//Create an UIImagePickerController to be able to take a picture
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsImageEditing = NO;
[self presentModalViewController:picker animated:YES];
[picker release];
- (IBAction)selectExistingPicture{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//Here is specified the fact that the picker source is the library
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error accessing photo library" message:#"Device does not support a photo library" delegate:nil cancelButtonTitle:#"Drat!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
int imageCase=0;
UIImage *imageSaved=rotateImage(image);
UIImage* imageNormal =scaleImage(imageSaved,imageCase);
imageView.image = imageNormal;
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
I really need to at least understand what is happening so any help would be really appreciated even if it is not the solution!
Thanks folks!
one possibility is that you need to call
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];