I am Developing a sencha Touch application and using phonegap for ios build.
I want to show a number toolbar on top of ios keyboard and get the number button action in textField.
I can show the toolbar on top of the keyboard but can't update the textFild values according with the button tap/ clik.Here is my code .Please help me to solve this issue. I did the code in MainViewController.m. I am not familiar with objective c.
#import "MainViewController.h"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShowNotification:) name:UIKeyboardDidShowNotification object:nil];
}
return self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark
- View lifecycle - (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (void) keyboardDidShowNotification:(NSNotification *)aNotification {
UIBarButtonItem *my0Button = [[UIBarButtonItem alloc] initWithTitle:#"0" style:UIBarButtonItemStyleBordered target:self action:#selector(addNumberToString:)];
UIBarButtonItem *my1Button = [[UIBarButtonItem alloc] initWithTitle:#"1" style:UIBarButtonItemStyleBordered target:self action:#selector(addNumberToString:)];
// UIToolbar *keyboardToolbar=nil;
UIToolbar *extraRow = [[UIToolbar alloc] init];
extraRow.barStyle = UIBarStyleDefault;
extraRow.translucent = YES;
extraRow.tintColor = [UIColor grayColor];
[extraRow sizeToFit];
NSArray *buttons = [NSArray arrayWithObjects: my0Button, my1Button, nil];
[extraRow setItems:buttons animated:YES];
NSArray *array = [[UIApplication sharedApplication] windows];
for (UIWindow* wind in array) {
for (UIView* currView in wind.subviews) {
if ([[currView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* perView in currView.subviews) {
if ([[perView description] hasPrefix:#"<UIWebFormAccessory"]) {
[currView addSubview:extraRow];
[perView removeFromSuperview];
}
}
}
}
}
}
-(void) addNumberToString: (id) sender {
// HERE I WANT TO SHOW THE BUTTON TEXT TO TEXTFIELD,
}
#end
Finally i got output.
UIButton *clickButton=sender;
UILabel *label=clickButton.titleLabel;
NSString *buttonText=label.text;
NSString *javaScript = [NSString stringWithFormat:#"var textField = document.activeElement;" "textField.value = textField.value+'%#';" "document.activeElement.form.submit();", buttonText];
[webView stringByEvaluatingJavaScriptFromString:javaScript];
Related
I am using IQKeyboardManagerSwift in my app. It is working perfectly in some ViewControllers I have to disable it's toolbar. According to documentation I should add viewcontrollers in which I want to disable toolbar in following array.
IQKeyboardManager.sharedManager().disabledToolbarClasses = []
Now It is working perfectly for TextFields in view controller. But problem is with TextFields inside webview. I have a viewcontroller in which I have to input data in fields inside WebView, for fields inside webview Toolbar is not disabled I tried many ways. Even disabling IQKeyBaord (IQKeyboardManager.sharedManager().enable = false) for whole app doesn't effect WebView
I do not understand what is the issue is there some specific handling for WebView or what can be possible alternate.
For clarification top view with Done button is toolbar that I am referring.
Toolbar over the keyboard is the default property/behaviour of WebView/WKWebView.
But if you want to remove it, here is the code, you can modify it according to your need :
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(removeKeyboardTopBar:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(removeKeyboardTopBar:) name:UIKeyboardDidShowNotification object:nil];
}
-(void)viewDidAppear:(BOOL)animated{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"https://html5doctor.com/demos/forms/forms-example.html"]];
[_webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) removeKeyboardTopBar:(NSNotification*)notify{
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
__block UIView* toolBarContainer = nil;
NSArray* windows = [[UIApplication sharedApplication] windows];
for (UIWindow *possibleWindow in windows) {
if (![[possibleWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = possibleWindow;
break;
}
}
for (UIView *possibleFormView in [keyboardWindow subviews])
{
if([[[UIDevice currentDevice] systemVersion] floatValue]>8){
if([[possibleFormView description] hasPrefix:#"<UIInputSetContainerView"])
{
for(int i = 0 ; i < [possibleFormView.subviews count] ; i++)
{
UIView* hostkeyboard = [possibleFormView.subviews objectAtIndex:i];
if([[hostkeyboard description] hasPrefix:#"<UIInputSetHostView"])
{
for (id temp in hostkeyboard.subviews)
{
if ([[temp description] hasPrefix:#"<UIWebFormAccessory"])
{
UIView* currentToolBar = (UIView*)temp;
currentToolBar.hidden = true;
toolBarContainer = hostkeyboard;
}
}
}
}
}
}else{
if ([[possibleFormView description] rangeOfString:#"UIPeripheralHostView"].location != NSNotFound) {
for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([[subviewWhichIsPossibleFormView description] rangeOfString:#"UIWebFormAccessory"].location != NSNotFound) {
[subviewWhichIsPossibleFormView removeFromSuperview];
}
}
}
}
}
if(toolBarContainer){
if([notify.name isEqualToString:#"UIKeyboardWillShowNotification"]){
[toolBarContainer setHidden:YES];
}else if([notify.name isEqualToString:#"UIKeyboardDidShowNotification"]){
[toolBarContainer setHidden:NO];
}
dispatch_async(dispatch_get_main_queue(), ^(){
toolBarContainer.frame = CGRectMake(toolBarContainer.frame.origin.x,toolBarContainer.frame.origin.y+44,toolBarContainer.frame.size.width,toolBarContainer.frame.size.height);
});
}
keyboardWindow = nil;
}
Recently, a strange question occurred when I pushViewController to the next viewController.
Why I think it's a strange question? because it don't always appears(The probability of occurrence is low). when it appears, next viewController only shows its nav bar on screen, I still can see the rootViewController, but touching it without reaction(PopGesture is effective).Hoping for your help, thanks very much.
#pragram mark - method of pushing
- (void)clickToAccout {
if (![self countTotalSelectedNumber]) {
[SVProgressHUD showInfoWithStatus:#"没有被选择的商品"];
return;
}
CSCreatOrderViewController *creatOrderVC = [[CSCreatOrderViewController alloc] init];
creatOrderVC.totalPrice = [self countTotalPrice];
creatOrderVC.goods = [self selectedGoods];
[self.navigationController pushViewController:creatOrderVC animated:YES];
}
#pragma mark - chlid class of navgationController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationBar.tintColor = [UIColor whiteColor];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return _barStyle;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
if (self.viewControllers.count > 0) {
viewController.hidesBottomBarWhenPushed = YES;
[SVProgressHUD dismiss];
}
[super pushViewController:viewController animated:animated];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
[SVProgressHUD dismiss];
return [super popViewControllerAnimated:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - tabBarController
- (void)viewDidLoad {
[super viewDidLoad];
CSTabBar *tabBar = [[CSTabBar alloc] init];
[self setValue:tabBar forKey:#"tabBar"];
[self.tabBar setTintColor:[UIColor cz_colorWithHex:0Xec5151]];
[self addChildViewControllerWithTitle:#"首页" imageName:#"home" controllerName:#"CSHomeViewController"];
[self addChildViewControllerWithTitle:#"分类" imageName:#"classify" controllerName:#"CSClassifyViewController"];
[self addChildViewControllerWithTitle:#"查询" imageName:#"search" controllerName:#"CSSearchViewController"];
[self addChildViewControllerWithTitle:#"购物车" imageName:#"cart" controllerName:#"CSShoppingCartViewController"];
[self addChildViewControllerWithTitle:#"我的" imageName:#"mine" controllerName:#"CSMineViewController"];
self.selectedIndex = 0;
}
- (void)addChildViewControllerWithTitle:(NSString *)title imageName:(NSString *)imageName controllerName:(NSString *)controllerName {
Class cls = NSClassFromString(controllerName);
UIViewController *vc = [[cls alloc] init];
vc.title = title;
[vc.tabBarItem setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#",imageName]]];
[vc.tabBarItem setSelectedImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#_selected",imageName]]];
vc.tabBarItem.title = title;
CSNavigationController *nav = [[CSNavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nav];
}
#pragma mark - base viewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self setupNavItem];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
_indciatorView = [[CSIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
UIWindow *keyW = [UIApplication sharedApplication].keyWindow;
[keyW addSubview:_indciatorView];
[_indciatorView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(keyW);
}];
}
- (void)setupNavItem {
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
button.imageEdgeInsets = UIEdgeInsetsMake(9, 0, 9, 29);
[button setImage:[UIImage imageNamed:#"left"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(clickToDismiss) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}
- (void)clickToDismiss {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
I think you should change
[super pushViewController:viewController animated:animated];
to
[self.navigationController pushViewController:viewController animated:animated];
And the same when pop
[super popViewControllerAnimated:animated];
to
[self.navigationController popViewControllerAnimated:animated];
I clear the cache of Xcode, this case don't appear. Maybe I Imported a third lib ago caused this case. But like what I asked ,it don't always appears(The probability of occurrence is low). So, hoping it has been well.
I need add all colors of my views to NSMuttableArray. A try do it, but adding only one color of last view. My Array named colorArray. Please help me.
I think it should be done in a loop, but I do not know exactly where its cause and how to describe it
It's my ViewController
#import "ViewController.h"
#import "RandomView.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize kol;
#synthesize sdvig1;
#synthesize sdvig2;
#synthesize myTextField;
#synthesize randView;
#synthesize redButton, greenButton, blueButton;
#synthesize colorArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
kol=10;
}
return self;
}
-(void) viewWillAppear:(BOOL)animated
{
myTextField.delegate = self;
kol=[[myTextField text] intValue];
}
- (void)viewDidLoad
{
[super viewDidLoad];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width/4, 30)];
myTextField.backgroundColor=[UIColor yellowColor];
[myTextField setKeyboardType:UIKeyboardTypeNumberPad];
[self.view addSubview:myTextField];
redButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4, 20, self.view.frame.size.width/4, 30)];
redButton.backgroundColor=[UIColor redColor];
[redButton addTarget: self
action: #selector(redSort:) forControlEvents: UIControlEventTouchUpInside];
greenButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4*2, 20, self.view.frame.size.width/4, 30)];
greenButton.backgroundColor=[UIColor greenColor];
[greenButton addTarget: self
action: #selector(greenSort:) forControlEvents: UIControlEventTouchUpInside];
blueButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4*3, 20, self.view.frame.size.width/4, 30)];
blueButton.backgroundColor=[UIColor blueColor];
[blueButton addTarget: self
action: #selector(blueSort:) forControlEvents: UIControlEventTouchUpInside];
[self.view addSubview:redButton];
[self.view addSubview:greenButton];
[self.view addSubview:blueButton];
[self createView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark- Создание и удаление View's
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[myTextField resignFirstResponder];
[self textFieldShouldReturn:myTextField];
myTextField.text = #"";
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([self.myTextField.text isEqualToString:#""]) {
} else
{
[self.myTextField resignFirstResponder];
kol=[[self.myTextField text] intValue];
[self removeView];
[self createView];
}
return YES;
}
-(void)createView{
colorArray= [[NSMuttableArray alloc] init];
sdvig1=self.view.frame.size.width/(2*(kol+5));
sdvig2=self.view.frame.size.height/(2*(kol+5));
randView = [[RandomView alloc] initWithFrame:CGRectMake(0,self.myTextField.frame.origin.y+self.myTextField.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-(self.myTextField.frame.origin.y+self.myTextField.frame.size.height)) count:kol sdvig:CGPointMake(sdvig1, sdvig2) vc:self];
[colorArray addObject:randView.backgroundColor]; //IT'S MY ARRAY
NSLog(#"colorArray= %#", colorArray);
[self.view addSubview:randView];
}
-(void) removeView{
[randView removeFromSuperview];
}
#pragma mark- Цвета
-(UIColor *) randomColor
{
CGFloat red = (CGFloat)arc4random() / (CGFloat)RAND_MAX;
CGFloat blue = (CGFloat)arc4random() / (CGFloat)RAND_MAX;
CGFloat green = (CGFloat)arc4random() / (CGFloat)RAND_MAX;
return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}
#end
And my View Class
//
// RandomView.m
// FewView
//
// Created by admin on 3/11/14.
// Copyright (c) 2014 admin. All rights reserved.
//
#import "RandomView.h"
#import "ViewController.h"
//#import <QuartzCore/QuartzCore.h>
#implementation RandomView
#synthesize randView;
//#synthesize myArray;
//#synthesize colorArrayRed, colorArrayBlue, colorArrayGreen, colorArray;
//#synthesize colorArray;
//CGFloat redBack, greenBack, blueBack, alphaBack;
- (id)initWithFrame:(CGRect)frame count:(NSInteger)kol sdvig:(CGPoint)sdvig vc:(ViewController*) delegat
{
self = [super initWithFrame:frame];
if (self)
{
// myArray = [[NSMutableArray alloc]init];
if (kol>0) {
[self setBackgroundColor:[delegat randomColor]];
randView = [[RandomView alloc] initWithFrame:CGRectMake(sdvig.x, sdvig.y, self. frame.size.width-2*sdvig.x, self.frame.size.height-2*sdvig.y) count:--kol sdvig:CGPointMake(sdvig.x, sdvig.y) vc:delegat];
self.layer.cornerRadius = 25;
self.layer.masksToBounds = YES;
[self addSubview:randView];
}
}
return self;
}
#end
Every time you call createView you're creating a new array. Try moving the colorArray = [[NSMutableArray alloc] init]; line into your viewDidLoad method.
I have been experimenting with some code in a sample project that uses xibs. In that project the below method takes a photo that was picked via UIImagePickerController and displays another VC modally initializing its scrollview with the image.
This works fine in the xib project but now that im integrating it into a storyboard project this section throws an exception:
SSPhotoCropperViewController *photoCropper =
[[SSPhotoCropperViewController alloc] initWithPhoto:nonRawImage
delegate:self
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
The error is:
'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/24FB2532-BB1D-4573-8551-386FAA154022/BubbleBoss.app> (loaded)' with name 'SSPhotoCropperViewController''
Which seems to be saying that its looking for the xib file that isnt there. I have created a mimicked storyboard version of the xib and hooked up all my actions and outlets the same.
How do I display a storyboard VC in the below method, set the scrollview photo to nonRawImage, pass it the min and max zoom as is done below?
Problem Method:
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:NO completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
UIImage *nonRawImage=[self scaleAndRotateImage:image];
SSPhotoCropperViewController *photoCropper =
[[SSPhotoCropperViewController alloc] initWithPhoto:nonRawImage
delegate:self
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
[photoCropper setMinZoomScale:0.25f];
[photoCropper setMaxZoomScale:3.00f];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:photoCropper];
[self presentViewController:nc animated:YES completion:nil];
// photoPreviewImageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
Code from SSPhotoCropperViewController.m
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
{
return [self initWithPhoto:aPhoto
delegate:aDelegate
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
}
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
uiMode:(SSPhotoCropperUIMode)uiMode
showsInfoButton:(BOOL)showsInfoButton
{
if (!(self = [super initWithNibName:#"SSPhotoCropperViewController" bundle:nil])) {
return self;
}
self.photo = aPhoto;
self.delegate = aDelegate;
_uiMode = uiMode;
_showsInfoButton = showsInfoButton;
self.minZoomScale = 0.5f;
self.maxZoomScale = 3.0f;
self.infoMessageTitle = #"In order to crop the photo";
self.infoMessageBody = #"Use two of your fingers to zoom in and out the photo and drag the"
#" green window to crop any part of the photo you would like to use.";
self.photoCropperTitle = #"Crop Photo";
return self;
}
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.photo = nil;
self.delegate = nil;
}
return self;
}
- (void) didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction) infoButtonTapped:(id)sender
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:self.infoMessageTitle
message:self.infoMessageBody
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[av show];
}
#pragma -
#pragma mark - View lifecycle
- (void) viewDidLoad
{
[super viewDidLoad];
//
// setup view ui
//
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(saveAndClose:)];
self.navigationItem.rightBarButtonItem = bi;
if (_uiMode == SSPCUIModePresentedAsModalViewController) {
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancelAndClose:)];
self.navigationItem.leftBarButtonItem = bi;
}
if (!_showsInfoButton) {
[self.infoButton setHidden:YES];
}
self.title = self.photoCropperTitle;
//
// photo cropper ui stuff
//
[self setScrollViewBackground];
[self.scrollView setMinimumZoomScale:self.minZoomScale];
[self.scrollView setMaximumZoomScale:self.maxZoomScale];
[self.cropRectangleButton addTarget:self
action:#selector(imageTouch:withEvent:)
forControlEvents:UIControlEventTouchDown];
[self.cropRectangleButton addTarget:self
action:#selector(imageMoved:withEvent:)
forControlEvents:UIControlEventTouchDragInside];
if (self.photo != nil) {
[self loadPhoto];
}
}
- (void) viewDidUnload
{
[super viewDidUnload];
}
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
#pragma -
#pragma UIScrollViewDelegate Methods
- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
#pragma -
#pragma Private Methods
- (void) loadPhoto
{
if (self.photo == nil) {
return;
}
CGFloat w = self.photo.size.width;
CGFloat h = self.photo.size.height;
CGRect imageViewFrame = CGRectMake(0.0f, 0.0f, roundf(w / 2.0f), roundf(h / 2.0f));
self.scrollView.contentSize = imageViewFrame.size;
UIImageView *iv = [[UIImageView alloc] initWithFrame:imageViewFrame];
iv.image = self.photo;
[self.scrollView addSubview:iv];
self.imageView = iv;
}
Ok ive got the method call changed to
SSPhotoCropperViewController *photoCropper =
[[SSPhotoCropperViewController alloc] initWithPhoto:photo
delegate:self
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
[photoCropper setMinZoomScale:0.25f];
[photoCropper setMaxZoomScale:3.00f];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:photoCropper];
But Im not sure what to do with the below:
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
uiMode:(SSPhotoCropperUIMode)uiMode
showsInfoButton:(BOOL)showsInfoButton
{
if (!(self = [super initWithNibName:#"SSPhotoCropperViewController" bundle:nil])) {
return self;
}
self.photo = aPhoto;
self.delegate = aDelegate;
_uiMode = uiMode;
_showsInfoButton = showsInfoButton;
self.minZoomScale = 0.5f;
self.maxZoomScale = 3.0f;
self.infoMessageTitle = #"In order to crop the photo";
self.infoMessageBody = #"Use two of your fingers to zoom in and out the photo and drag the"
#" green window to crop any part of the photo you would like to use.";
self.photoCropperTitle = #"Crop Photo";
return self;
}
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.photo = nil;
self.delegate = nil;
}
return self;
}
You should give your view controller an identifier within the storyboard, then instantiate it as follows:
YourViewControllerClass *viewController =
[[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil]
instantiateViewControllerWithIdentifier:#"ViewController"];
The identifier can be set using Storyboard ID from within the Identity Inspector.
Make sure you set the SSPhotoCropperViewController's Identifier in the storyboard to SSPhotoCropperViewController.
Change your method:
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
uiMode:(SSPhotoCropperUIMode)uiMode
showsInfoButton:(BOOL)showsInfoButton
{
//if (!(self = [super initWithNibName:#"SSPhotoCropperViewController" bundle:nil])) {
if (!(self = [[UIStoryboard storyboardWithName:#"YourStoryBoardName" bundle:nil]
instantiateViewControllerWithIdentifier:#"SSPhotoCropperViewController"])) {
return self;
}
self.photo = aPhoto;
self.delegate = aDelegate;
_uiMode = uiMode;
_showsInfoButton = showsInfoButton;
self.minZoomScale = 0.5f;
self.maxZoomScale = 3.0f;
self.infoMessageTitle = #"In order to crop the photo";
self.infoMessageBody = #"Use two of your fingers to zoom in and out the photo and drag the"
#" green window to crop any part of the photo you would like to use.";
self.photoCropperTitle = #"Crop Photo";
return self;
}
This is amongst the oddest issues with iOS development I have ever seen. I'm relatively new to iOS development, so I apologize if I'm missing something obvious or my terminology isn't completely correct. If you need clarification, please let me know in the comments and I'll edit my question accordingly.
The Problem
I'm using Three20, so that might have something to do with it. But I have a "Home view" which is basically a series of images that link out to other views (shown in the image below). If I start our in portrait view, all is well.
The next view is a table view, shown below:
YAY! I can rotate and all is right with the world. BUT if I go back to that home view, rotate to landscape, and THEN go to this tabled view, the world breaks.
You'll see that there's a random space added to the right side of my table now. I don't know where and how it came from. Here's my Controller.m file:
#import "FriendTabsController.h"
#import "MyAppApp.h"
#import "JohnDoeManager.h"
#implementation FriendTabsController
#synthesize innerView, segmentedControl, innerController, friendsController, friendRequestsController;
- (void)addBottomGutter:(UIViewController*)controller {
if ([controller isKindOfClass:[TTTableViewController class]]) {
TTTableViewController* tableViewController = (TTTableViewController*)controller;
tableViewController.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,50+44,0);
tableViewController.tableView.contentInset = UIEdgeInsetsMake(0,0,50+44,0);
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Friends";
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
friendsController = [[FriendsController alloc] init];
friendRequestsController = [[FriendsController alloc] init];
((FriendsController*)friendRequestsController).friendRequests = YES;
[self addBottomGutter:friendsController];
[self addBottomGutter:friendRequestsController];
innerController = friendsController;
[innerView addSubview:innerController.view];
[innerController viewDidLoad];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
[self loadBannerAd:(orientation)];
}
-(void) loadBannerAd:(UIInterfaceOrientation)orientation{
MainLayer *mi = [MainLayer getInstance];
if (mi.useJohnDoeAds) {
[[JohnDoeManager sharedInstance] setCurrentViewController:self];
[mi.JohnDoeBanner.view removeFromSuperview];
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// This is a portait ad
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 410-44, 320, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake(0, 1024-44-90-20, 768, 90)];
}
} else {
// Landscape
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 320-44-58, 410, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake((1024-768)/2, 768-44-90-20, 768, 90)];
}
}
[self.view addSubview:mi.JohnDoeBanner.view];
[mi.JohnDoeBanner rollOver];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self loadBannerAd:(toInterfaceOrientation)];
}
- (IBAction)didChangeSegment:(UISegmentedControl *)control {
if (innerController) {
[innerController viewWillDisappear:NO];
[innerController.view removeFromSuperview];
[innerController viewDidDisappear:NO];
}
switch (control.selectedSegmentIndex) {
case 0:
innerController = friendsController;
self.title = #"Friends";
break;
case 1:
innerController = friendRequestsController;
self.title = #"Requests";
break;
}
[innerController viewWillAppear:NO];
[innerView addSubview:innerController.view];
[innerController viewDidAppear:NO];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[innerController viewWillAppear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[innerController viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[innerController viewWillDisappear:animated];
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[innerController viewDidDisappear:animated];
[super viewDidDisappear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[friendsController release], friendsController = nil;
[friendRequestsController release], friendRequestsController = nil;
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
#end
So can someone please tell me what's going on? HELP!
You need to set wantsFullScreenLayout property to YES.
in your init methods set
self.wantsFullScreenLayout = YES;
This will solve your problem.