UIAlert with AddSubview replacement for iOS 7 - objective-c

Current code works perfectly before iOS 7, on iOS 7 there is no field to input the name of the user, from scanning these forums I noticed t changed on iOS7 something to do with the addsubview function, here is the current code;
Could anyone assist in converting this to work with iOS7 (ideally not breaking the iOS 6 link as would prefer to keep the app compatible with both OS versions)
- (void) createScoreInput {
changePlayerAlert = [UIAlertView new];
changePlayerAlert.title = #"Enter your name";
changePlayerAlert.message = #"\n\n";
changePlayerAlert.delegate = self;
[changePlayerAlert addButtonWithTitle:#"Save"];
[changePlayerAlert addButtonWithTitle:#"Cancel"];
CGRect frame = changePlayerAlert.frame;
frame.origin.y -= 100.0f;
changePlayerAlert.frame = frame;
changePlayerTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 245, 27)];
changePlayerTextField.borderStyle = UITextBorderStyleRoundedRect;
[changePlayerAlert addSubview:changePlayerTextField];
changePlayerTextField.keyboardType = UIKeyboardTypeNamePhonePad;
changePlayerTextField.returnKeyType = UIReturnKeyDone;
changePlayerTextField.autocorrectionType = UITextAutocorrectionTypeNo;
changePlayerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
changePlayerTextField.delegate = self;
}

This API has solution for your problem use this and have fun
https://github.com/Darktt/DTAlertView
https://github.com/Scott90/SDCAlertView
https://github.com/lmcd/LMAlertView
OR
Follow this tutorial and you can take input directly from UIAlertView

Related

NSWindow beginSheet:completionHandler With No Response Buttons

I understand that NSApp's beginSheet:modalForWindow is deprecated for OS X 10.10. So I need a replacement for it. The thing is that I only want to show a window sheet with a progress wheel and no okay or cancel buttons while some work is under way with performSelectorOnMainThread:withObject:waitUntilDone. Anyway, I have written the following lines of code for Objective-C and Swift.
- (void)Backgroundwork :(NSWindow *)window :(NSString *)labelMsg {
NSRect sheetRect = NSMakeRect(0,0,400,114);
NSWindow *progSheet = [[NSWindow alloc] initWithContentRect:sheetRect styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:YES];
NSView *contentView = [[NSView alloc] initWithFrame:sheetRect];
NSProgressIndicator *progInd = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(190,74,20,20)];
[progInd setStyle:NSProgressIndicatorSpinningStyle];
NSTextField *messageLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(20,20,240,46)];
messageLabel.stringValue = labelMsg;
[messageLabel setBezeled:NO];
[messageLabel setDrawsBackground:NO];
[messageLabel setEditable:NO];
[messageLabel setSelectable:NO];
[contentView addSubview:messageLabel];
[contentView addSubview:progInd];
[progSheet setContentView:contentView];
[window beginSheet:progSheet completionHandler:^(NSModalResponse returnCode) {
// some work
}];
}
func Backgroundwork(window:NSWindow,labelMsg:String) -> Void {
let sheetRect:NSRect = NSMakeRect(0,0,400,114)
let progSheet:NSWindow = NSWindow.init(contentRect:sheetRect, styleMask:NSTitledWindowMask,backing:NSBackingStoreType.Buffered,`defer`:true)
let contentView:NSView = NSView.init(frame:sheetRect)
let progInd:NSProgressIndicator = NSProgressIndicator.init(frame:NSMakeRect(190,74,20,20))
progInd.style = NSProgressIndicatorStyle.SpinningStyle
let msgLabel:NSTextField = NSTextField.init(frame:NSMakeRect(20,20,240,46))
msgLabel.stringValue = labelMsg;
msgLabel.bezeled = false
msgLabel.drawsBackground = false
msgLabel.editable = false
msgLabel.selectable = false
contentView.addSubview(msgLabel)
contentView.addSubview(progInd)
progSheet.contentView = contentView
window.beginSheet(progSheet) {(NSModalResponse) -> Void in
// some work
}
}
If I'm correct, NSWindow's beginSheet:completionHandler requires response buttons. So the application never enters the beginSheet bloc in the code above. Right? Or can I still use beginSheet:completionHandler without response (okay,cancel) buttons? Or do I have to use something else other than beginSheet like a modal window that I have to open and close?
Thanks.
Update 1
Maybe, making it a modal window with NSModalSession is the best alternative?
let session:NSModalSession = NSApp.beginModalSessionForWindow(progSheet)
This approach seems to conform to OS X 10.10.

iOS 7.1 imagePicker CameraFlashMode not indicating ON/OFF state

iOS 7.1 imagePicker CameraFlashMode not indicating ON/OFF state
I have iPhone application which overlays the camera with custom view. I have a button to switch between camera flash mode, this is the code.
self.imagePickerController.cameraFlashMode always displays auto mode.
if ( self.imagePickerController.cameraFlashMode == UIImagePickerControllerCameraFlashModeOn) {
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
[self.flashButton setImage:[UIImage imageNamed:#"flashoff.png"] forState:UIControlStateNormal];
self.flashButton.selected = NO;
}
else
{
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
[self.flashButton setImage:[UIImage imageNamed:#"flash.png"] forState:UIControlStateNormal];
self.flashButton.selected = YES;
}
NSLog(#"cameraFlashMode: %d",self.imagePickerController.cameraFlashMode);
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:self.imagePickerController.cameraFlashMode] forKey:#"cameraFlashMode"];
When you do:
self.imagePickerController = [[UIImagePickerController alloc] init];
[self.imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[self.imagePickerController setCameraCaptureMode:UIImagePickerControllerCameraCaptureModePhoto];
//...
(in your particular case) explicitly mention:
[imagePickerController setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
If you don't then the camera defaults to UIImagePickerControllerCameraFlashModeAuto
and since the logic you've implemented doesn't handle this case, it remains in UIImagePickerControllerCameraFlashModeAuto

How to disable Preview screen when using UIImagePickerController Camera

In iOS7 the build-in camera app doesn't go into the preview screen after taking a picture, is there any way that the UIImagePicker can behave like that.
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
I know another solution is to create a custom camera using the AVFoundation class, but that is beyond my knowledge at this point and I really like the looks of the default camera.
Update
So after some more research I found out I could create my own shutter button and set it as a camera overlay. Here is what I did
UIButton *shutter = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[shutter addTarget:self action:#selector(shootPicture) forControlEvents:UIControlEventTouchUpInside];
[shutter setTitle:#"S" forState:UIControlStateNormal];
shutter.frame = CGRectMake(50, 50, 60, 60);
UIView *layoutView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
layoutView.opaque = NO;
layoutView.backgroundColor = [UIColor clearColor];
[layoutView addSubview:shutter];
For the 'shootPicture' method
- (void) shootPicture
{
[picker takePicture];
[self imagePickerController:self.camCtl didFinishPickingMediaWithInfo:nil];
}
If I just have the picker call 'takePicture' I will still get the preview, so instead I forced the picker to call didFinishPickingMediaWithInfo right after taking picture. The result is I don't see the preview screen HOWEVER I don't see the picture either. I know I put 'nil' in didFinishPickingMediaWithInfo because I don't know what to put in at this point. I also know it took a picture is in cache somewhere but I really have no idea how to get it.
Any idea would be greatly appreciated =)
This solution works for me:
self.pickerController.allowsEditing = false

UIScrollView buggy

Please excuse poor code atm, just trying to get it working before making it look nice. So I am trying to get UIScrollView working. If I remove all scroll view stuff, I have a nicely laid out page with 64 buttons, 32 on each side of the page. These buttons are nigh miniature; so I wanted to implement zoom to be able to click them.
Zoom currently has unexpected results. When the page starts, it is blank. Zooming unexpectedly shows some of the left side of the graph on the rigght side of the page, and it bounces as I try to scroll over towards it. But when I zoom more, it allows me to scroll more towards the middle of the buttons. Always giving me difficulties/bugging out as I scroll/zoom. So obviously unusable.
My viewDidLoad:
[super viewDidLoad];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.minimumZoomScale = 0.5;
scroll.maximumZoomScale = 3.0;
scroll.delegate = self;
CGFloat yOrigin = self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
// iterate over values in the staff array
int heightBetweenBrackets = 0;
int widthBetweenBrackets = 0;
int heightFromTop = 45;
for(int i = 0; i < 64; i++)
{
if(i == 32)
{
heightBetweenBrackets = 0;
}
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(
0 + i/32*438,
heightFromTop + i%32*3+ heightBetweenBrackets,
35, 6);
[myButton setTitle:[NSString stringWithFormat:#"%d",i] forState:UIControlStateNormal];
myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[myButton.titleLabel setFont:[UIFont fontWithName:#"Arial" size:7]];
myButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
// [myButton addTarget:self action:#selector(chooseWinner:) forControlEvents:UIControlEventTouchUpInside];
[awesomeView addSubview:myButton];
heightBetweenBrackets += (i%2 -1 * -1) * 3;
}
[scroll addSubview:awesomeView];
scroll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:scroll];
and:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.view;
}
I apologize if the bug is stupid I'm just learning IOS =] thanks for your time
EDIT: Figured it out.
For anybody in the future: I ported over a pagination scroller, and didn't realize I had kept CGFloat yOrigin = self.view.frame.size.width; -- this of course was starting the view directly to the right of any visible space. Thus I was able to zoom and see the left of it, in a buggy manner, although it started out blank. Simply changing this to 0 solved my problem.
For anybody in the future: I ported over a pagination scroller, and didn't realize I had kept CGFloat yOrigin = self.view.frame.size.width; -- this of course was starting the view directly to the right of any visible space. Thus I was able to zoom and see the left of it, in a buggy manner, although it started out blank. Simply changing this to 0 solved my problem.

problem with changing view

hi I have a problem I made an application based on apples sample app called photoscroller and i want to add a login screen.but when i add it the showed view move upward 10-15 pixels and the main window is visible underneath.I ask why?
Parts of my code:
at view did load:
InfoViewController *infoView = [[InfoViewController alloc] initWithNibName:nil bundle:nil];
self.view = infoView.view;
[infoView release];
then later after validating the login:
CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
pagingScrollView.delegate = self;
self.view = pagingScrollView;
...
I do not know why is pushed upward when i add other view.
thank for every answer
Could you past the method - (CGRect) frameForPagingScrollView, without that method it's bit harder to understand your code.
But i guess the self.view.frame and the CGRect returned from that method differ.
Further guess would be, that the difference are not 10-15 pixels, but 20 pixels (for the height of the UIStatusBar), which might be enabled in your .xib-File but is actually not displayed.