Does adding a subview to SDCAlertView work properly on iOS 8? - ios8

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

Related

Activity Indicator will not go away

I am using the following code to show an Activity Indicator while some data is loading. The problem is that when I try to hide it again. The Activity Indicator stays put. The screen lightens a bit but that is it.
To show it:
self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.activityIndicator startAnimating];
[self.tableView addSubview:self.overlayView];
To hide it:
[self.activityIndicator stopAnimating];
[self.overlayView removeFromSuperview];
Try to add your overlayView to the superview of your tableView :
[self.view.superview addSubview:self.overlayView];
I figured it out with a combination of stackoverflow questions. Here is my code to show the UIActivityIndicatorView
-(void)loadView {
[super loadView];
self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.tableView addSubview:self.overlayView];
[self.activityIndicator startAnimating];
}
Here is the code to hide it. It looks like putting the code in the loadView event made all the difference.
[overlayView removeFromSuperview];

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);
}
}

InputAccessoryView of a UITextField

I need to stick a toolBar with a UITextField inside to a keyboard.
What if I make the whole toolBar (which I think is the textField's super view) the inputAccessoryView of its textField?
I mean like this:
textField.inputAccessoryView = toolBar; // textField is inside the toolBar
I've been trying on this but I have not made it work yet.
Anyone can help?
Or is there another way to achieve what I want?
- (void)viewDidLoad
{
[self createAccessoryView];
[textField setDelegate:self];
[textField setKeyboardType:UIKeyboardTypeDefault];
[textField setInputAccessoryView:fieldAccessoryView];
}
- (void)createAccessoryView
{
CGRect frame = CGRectMake(0.0, self.view.bounds.size.height, self.view.bounds.size.width, 44.0);
fieldAccessoryView = [[UIToolbar alloc] initWithFrame:frame];
fieldAccessoryView.barStyle = UIBarStyleBlackOpaque;
fieldAccessoryView.tag = 200;
[fieldAccessoryView setBarStyle:UIBarStyleBlack];
UIBarButtonItem *spaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(done:)];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(#"Previous", #""), NSLocalizedString(#"Next", #""), nil]];
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl setMomentary:YES];
UIBarButtonItem *segmentButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[fieldAccessoryView setItems:[NSArray arrayWithObjects:segmentButton, spaceButton, doneButton, nil] animated:NO];
[segmentButton release];
[spaceButton release];
[doneButton release];
[segmentedControl release];
}
When are you setting the property? You may be setting it after the view has already loaded.
Try setting it in
- (void) viewDidLoad

SIGABRT error during interface change

(IBAction)switchAppointment {
AppointmentController *appt = [[AppointmentController alloc] initWithNibName:nil bundle:nil];
appt.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:appt animated:YES];
[appt release];
}
That is the code that I use to switch from one .xib to another, however on the line that says "self presentModalViewController:appt animated:YES" , I'm getting a SIGABRT error. My app crashes immediately when I try to go into that interface.
FYI too I'm on Xcode 4.2, but it was doing this before I downloaded the beta.
I have also same answer for the code:
nextView *second=[[nextView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
Yours
Miska

UIImage Picker autorotation feature disappeared suddenly

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];

Resources