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;
}
Related
I have created one application in Objective C. I want to implement functionality for showing selected content area of the screen on external display. For example, I have total 10 screens and I want to show 4 screens and don't want to show entire portion of the screen, just want to show selected view and area of the screen in external display.
I have done research on this, I found one tutorial, but that tutorial is available in swift language and I want to implement this things in objective c language.
The Swift tutorial in Objective C Code:
#import "ViewController.h"
#import "ExternalScreenViewController.h"
#interface ViewController ()
{
UIWindow *externalWindow;
UIWebView *webView;
}
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
webView = [[UIWebView alloc] init];
[self setupScreenNotifications];
NSURL *url = [NSURL URLWithString:#"http://www.spazstik-software.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];
if ([[UIScreen screens] count] > 1) {
[self setupExternalScreen:[UIScreen screens][1]];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setupScreenNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(externalScreenDidConnect:) name:UIScreenDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(externalScreenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];
}
-(void)externalScreenDidConnect:(NSNotification *)notification {
UIScreen *screen = (UIScreen *)[notification object];
if (screen != nil) {
[self setupExternalScreen:screen];
}
}
-(void)externalScreenDidDisconnect:(NSNotification *)notification {
id obj = [notification object];
if (obj != nil) {
[self teardownExternalScreen];
}
}
-(void)setupExternalScreen:(UIScreen *)screen {
ExternalScreenViewController *vc = [[self storyboard] instantiateViewControllerWithIdentifier:#"ExternalScreen"];
externalWindow = [[UIWindow alloc]initWithFrame:screen.bounds];
externalWindow.rootViewController = vc;
externalWindow.screen = screen;
externalWindow.hidden = false;
}
-(void)teardownExternalScreen {
if (externalWindow != nil) {
externalWindow.hidden = true;
externalWindow = nil;
}
}
#end
For iOS 13 and up change the setupExternalScreen method to this
source : https://stackoverflow.com/a/61474635/9777391
-(void)setupExternalScreen:(UIScreen *)screen shouldRecurse:(bool)recurse {
UIWindowScene* matchingWindowScene = nil;
// For iOS13 and up find matching UIWindowScene
for(UIScene *aScene in UIApplication.sharedApplication.connectedScenes){
UIWindowScene *windowScene = (UIWindowScene*)aScene;
// Look for UIWindowScene that has matching screen
if (windowScene.screen == screen) {
matchingWindowScene = windowScene;
break;
}
}
if (matchingWindowScene == nil) {
// UIWindowScene has not been created by iOS rendered yet
// Lets recall self after delay of two seconds
if (recurse) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self setupExternalScreen:screen shouldRecurse:NO];
});
}
// Dont proceed further if none found
return;
}
// Instantiate view controller
ExternalScreenViewController *vc = [[self storyboard] instantiateViewControllerWithIdentifier:#"ExternalScreen"];
// Setup external window
externalWindow = [[UIWindow alloc] initWithFrame:screen.bounds];
[externalWindow setRootViewController: vc];
// Set scene
[externalWindow setWindowScene:matchingWindowScene];
// Show the window.
[externalWindow setHidden:NO];
}
I am trying to use pure code to create UI practice block pass value between viewController. But the callback block didn't work. The NSLog method didn't print anything on debug area. Here's the code. Give me some tips, thank you.
VC.h
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController
#property (copy, nonatomic) void (^callBack)(NSString *text);
#end
VC.m
- (UITextField *)textField {
if (!_textField) {
_textField = [[UITextField alloc] init];
_textField.backgroundColor = [UIColor whiteColor];
}
return _textField;
}
- (UIButton *)button {
if (!_button) {
_button = [[UIButton alloc] init];
_button.backgroundColor = [UIColor blueColor];
[_button addTarget:self action:#selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
}
return _button;
}
- (void)setupUI {
[self.view addSubview:self.textField];
[self.view addSubview:self.button];
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(200);
make.height.mas_equalTo(50);
make.centerX.mas_equalTo(self.view.mas_centerX);
make.centerY.mas_equalTo(self.view);
}];
[self.button mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(200);
make.height.mas_equalTo(50);
make.centerX.mas_equalTo(self.view);
make.centerY.mas_equalTo(self.view).offset(100);
}];
}
- (void)buttonAction {
NSString *str = self.textField.text;
if (self.callBack != nil) {
self.callBack(str);
NSLog(#"This statement didnt print in log");
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupUI];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
}
update code
VC2.m
- (void)viewWillAppear:(BOOL)animated{
self.callBack = ^(NSString *text){
};
}
- (void)buttonAction {
if (self.callBack) {
NSLog(#"It worked on debug area %#", self.textField.text);
self.callBack(self.textField.text);
}
self.textField.text = #"";
}
VC1.m
- (void)viewDidLoad {
[super viewDidLoad];
_secondVc = [[SecondViewController alloc] init];
_secondVc.callBack = ^(NSString *str){
};
[self setupUI];
self.view.backgroundColor = [UIColor greenColor];
}
- (void)viewWillAppear:(BOOL)animated {
if (_secondVc.callBack != nil) {
NSLog(#"It wrked on debug screen");
_secondVc.callBack = ^(NSString *str){
NSLog(#"It didn't worked on debug screen");
//I want set my label.text = str;
};
};
}
The only way is that you property
#property (copy, nonatomic) void (^callBack)(NSString *text);
is empty. Try to put breakpoint in buttonAction method and look at the property.
As Sander and KrishnaCA mentioned your callBack is nil. I would suggest you create a definition of the block like this:
typedef void(^TextBlock)(NSString *text);
Then change your property to:
#property (copy, nonatomic) TextBlock callBack;
Create a copy of the block in your first view controller:
#interface FirstViewController()
#property (copy, nonatomic) TextBlock firstViewControllerCallBack;
#end
Initialize the callback copy (i.e. in viewDidLoad)
- (void)viewDidLoad {
[super viewDidLoad];
self.firstViewControllerCallBack = ^(NSString *text){
NSLog(#"Second view controller's button tapped!");
};
}
Assign the callback to the second view controller right before presenting/pushing it:
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.callBack = self.firstViewControllerCallBack; // Assign the callback
// ... Presenting the view controller
Clean up the completion block after you done with it (i.e. in viewWillDisappear):
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.firstViewControllerCallBack = nil;
}
In my app I've to create a custom alert view like the following:
So I followed this tutorial to create a custom alert view. I finished it but I'm getting issue in the following method:
- (void)addOrRemoveButtonWithTag:(int)tag andActionToPerform:(BOOL)shouldRemove {
NSMutableArray *items = [[NSMutableArray alloc]init];
[items addObject:self.buttonOk];
[items addObject:self.buttonClose];
int buttonIndex = (tag == 1);
if (shouldRemove) {
[items removeObjectAtIndex:buttonIndex];
} else {
if (tag == 1) {
[items insertObject:self.buttonOk atIndex:buttonIndex];
} else {
[items insertObject:self.buttonClose atIndex:buttonIndex];
}
}
}
I edited it than the tutorial because I don't need a UIToolBar for buttons. When I run the app it says me that I can't insert a nil object in an NSMutableArray, but I don't understand what's wrong, I hope you can help me to fix this issue.
UPDATE
Here's all the class code I developed:
#import "CustomAlertViewController.h"
#define ANIMATION_DURATION 0.25
#interface CustomAlertViewController ()
- (IBAction)buttonOk:(UIButton *)sender;
- (IBAction)buttonCancel:(UIButton *)sender;
#property (weak, nonatomic) IBOutlet UIButton *buttonClose;
#property (weak, nonatomic) IBOutlet UIButton *buttonOk;
#property (strong, nonatomic) IBOutlet UIView *viewAlert;
-(void)addOrRemoveButtonWithTag:(int)tag andActionToPerform:(BOOL)shouldRemove;
#end
#implementation CustomAlertViewController
- (id)init
{
self = [super init];
if (self) {
[self.viewAlert setFrame:CGRectMake(self.labelAlertView.frame.origin.x,
self.labelAlertView.frame.origin.y,
self.labelAlertView.frame.size.width,
self.viewAlert.frame.size.height)];
[self.buttonOk setTag:1];
[self.buttonClose setTag:0];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)showCustomAlertInView:(UIView *)targetView withMessage:(NSString *)message {
CGFloat statusBarOffset;
if (![[UIApplication sharedApplication] isStatusBarHidden]) {
CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
if (statusBarSize.width < statusBarSize.height) {
statusBarOffset = statusBarSize.width;
} else {
statusBarOffset = statusBarSize.height;
}
} else {
statusBarOffset = 0.0;
}
CGFloat width, height, offsetX, offsetY;
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft ||
[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
width = targetView.frame.size.width;
height = targetView.frame.size.height;
offsetX = 0.0;
offsetY = -statusBarOffset;
}
[self.view setFrame:CGRectMake(targetView.frame.origin.x, targetView.frame.origin.y, width, height)];
[self.view setFrame:CGRectOffset(self.view.frame, offsetX, offsetY)];
[targetView addSubview:self.view];
[self.viewAlert setFrame:CGRectMake(0.0, -self.viewAlert.frame.size.height, self.viewAlert.frame.size.width, self.viewAlert.frame.size.height)];
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.viewAlert setFrame:CGRectMake(0.0, 0.0, self.viewAlert.frame.size.width, self.viewAlert.frame.size.height)];
[UIView commitAnimations];
[self.labelAlertView setText:#"CIAO"];
}
- (void)removeCustomAlertFromView {
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.viewAlert setFrame:CGRectMake(0.0, -self.viewAlert.frame.size.height, self.viewAlert.frame.size.width, self.viewAlert.frame.size.height)];
[UIView commitAnimations];
[self.view performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
}
- (void)removeCustomAlertFromViewInstantly {
[self.view removeFromSuperview];
}
- (BOOL)isOkayButtonRemoved {
if (self.buttonOk == nil) {
return YES;
} else {
return NO;
}
}
- (BOOL)isCancelButtonRemoved {
if (self.buttonClose == nil) {
return YES;
} else {
return NO;
}
}
- (void)removeOkayButton:(BOOL)shouldRemove {
if ([self isOkayButtonRemoved] != shouldRemove) {
[self addOrRemoveButtonWithTag:1 andActionToPerform:shouldRemove];
}
}
- (void)removeCancelButton:(BOOL)shouldRemove {
if ([self isCancelButtonRemoved] != shouldRemove) {
[self addOrRemoveButtonWithTag:0 andActionToPerform:shouldRemove];
}
}
- (void)addOrRemoveButtonWithTag:(int)tag andActionToPerform:(BOOL)shouldRemove {
NSMutableArray *items = [[NSMutableArray alloc]init];
[items addObject:self.buttonOk];
[items addObject:self.buttonClose];
int buttonIndex = (tag == 1);
if (shouldRemove) {
[items removeObjectAtIndex:buttonIndex];
} else {
if (tag == 1) {
[items insertObject:self.buttonOk atIndex:buttonIndex];
} else {
[items insertObject:self.buttonClose atIndex:buttonIndex];
}
}
}
- (IBAction)buttonOk:(UIButton *)sender {
[self.delegate customAlertOk];
}
- (IBAction)buttonCancel:(UIButton *)sender {
[self.delegate customAlertCancel];
}
#end
UPDATE 2
Code in which I use the CustomAlertView:
#import "PromotionsViewController.h"
#import "CustomAlertViewController.h"
#interface PromotionsViewController () <CustomAlertViewControllerDelegate> {
BOOL isDeletingItem;
}
#property(nonatomic,strong) CustomAlertViewController *customAlert;
- (IBAction)buttonBack:(UIButton *)sender;
#property (weak, nonatomic) IBOutlet UIButton *buttonAlert;
- (IBAction)buttonAlert:(UIButton *)sender;
#end
#implementation PromotionsViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.buttonAlert setTitle:self.promotionSelected forState:UIControlStateNormal];
[self.customAlert setDelegate:self];
isDeletingItem = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonBack:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [[CustomAlertViewController alloc]init];
[self.customAlert removeOkayButton:NO];
[self.customAlert removeCancelButton:NO];
NSString *message = [NSString stringWithFormat:#"La tua offerta %# del 20%% è stata convertita in punti IoSi x10", self.promotionSelected];
[self.customAlert showCustomAlertInView:self.view withMessage:message];
isDeletingItem = YES;
}
- (void)customAlertOk {
if (isDeletingItem) {
[self.customAlert removeCustomAlertFromViewInstantly];
} else {
[self.customAlert removeCustomAlertFromView];
}
}
- (void)customAlertCancel {
[self.customAlert removeCustomAlertFromView];
if (isDeletingItem) {
isDeletingItem = NO;
}
}
#end
Maybe you're calling addOrRemoveButtonWithTag:andActionToPerform: at a time where your UI is not fully created, since UI elements are created asynchronously. So if you call this method, right after custom alert view instanciation, you'll get your crash because the buttons in the view are not created.
To solve this issue, you need to call addOrRemoveButtonWithTag:andActionToPerform: only once your custom alert has been added to the view hierarchy.
EDIT :
With the example code you gave in edit 2, you call these lines :
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [[CustomAlertViewController alloc]init];
[self.customAlert removeOkayButton:NO];
[self.customAlert removeCancelButton:NO];
}
but when you have just instantiated CustomAlertViewController, its 2 buttons are not yet created, so I suggest you add 2 properties hasOkButton and hasCancelButton and a new constructor to your custom class like this one :
- (instancetype) initWithOk:(BOOL)OkButton AndCancel:(BOOL) CancelButton
{
if(self = [super init])
{
hasOkButton = OkButton;
hasCancelButton = CancelButton;
}
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// At this time, the custom UI buttons will be created in the UI view hierarchy
[self removeOkayButton: hasOkButton];
[self removeOkayButton: hasCancelButton];
}
And in the caller you can use the following to display a custom alert View:
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [[CustomAlertViewController alloc] initWithOk:NO AndCancel:NO];
// ...
}
EDIT #2
I tried your solution in a real project, I made it work by using these lines int the caller :
- (IBAction)buttonAlert:(UIButton *)sender {
self.customAlert = [self.storyboard instantiateViewControllerWithIdentifier:#"customAlertView"];
self.customAlert.hasOK = NO;
self.customAlert.hasCancel = YES;
NSString *message = [NSString stringWithFormat:#"La tua offerta %# del 20%% è stata convertita in punti IoSi x10", self.promotionSelected];
[self.customAlert showCustomAlertInView:self.view withMessage:message];
isDeletingItem = YES;
}
In the CustomAlertViewController declare 2 visible properties hasOK and hasCancel in.h.
And modify your .m by adding method :
-(void)viewWillAppear:(BOOL)animated
{
[self removeOkayButton:self.hasOK];
[self removeCancelButton:self.hasCancel];
}
Be sure to modify your storyboard (if eligible) to have the "customAlertView" defined this way :
Don't forget also to bind your UIButton to the controller this can be a mistake too in your implementation :
Hope this will help you :)
I found on the web a tutorial to create custom alert view by using code, if you are interested you can go to this tutorial. I used it for my issue and it worked great! You have to fix a few things, because it uses deprecated command but it's easy to fix it.
If you are interested just take a look about this tutorial. I think you can integrate it in your app and after you can easily use for other stuff if it's necessary. I hope that my answer will help someone.
i got weird result on my app. when i pressed back button its always call scrollViewDidScroll and it makes my app crash.
error not happen if i'm not scrolling to the bottom (just load the view and then pressed back button).
but when i scrolled to the bottom and then press back button it force quit.
also no error if i'm scrolling to the bottom then scroll again back to the middle of tableview.
here is my code snippet.
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Securities Instructions";
currentPage = 1;
isReloading = NO;
totalPages = 1;
isScrollingEnable = YES;
...... bla bla bla....
[self.tableView reloadData];
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 90, 0); //values passed are - top, left, bottom, right
}
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// back button was pressed. We know this is true because self is no longer
// in the navigation stack.
NSLog(#"back button pressed");
isScrollingEnable = NO;
}
// [super viewWillDisappear:animated];
}
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
NSLog(#"scroll view called");
if (isScrollingEnable) {
NSLog(#"scroll view get called: scroll enalbe");
CGPoint offset = aScrollView.contentOffset;
CGRect bounds = aScrollView.bounds;
CGSize size = aScrollView.contentSize;
UIEdgeInsets inset = aScrollView.contentInset;
float y = offset.y + bounds.size.height - inset.bottom;
float h = size.height;
float reload_distance = 20;
if(y > h + reload_distance) {
if (isReloading==NO) {
if (totalPages>1) {
if (currentPage<totalPages) {
NSLog(#"scroll view called");
currentPage++;
isReloading = YES;
[self getJsonOnLoad];
}
}
}
}
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(#"index:%d",buttonIndex);
if (buttonIndex==0) {
if (totalPages!=9999) {
[self.navigationController popViewControllerAnimated:YES];
}
}
}
- (void) getTotalPages{
NSArray *detailArray = [self.jsonResult objectForKey:#"detail"];
int detailCount = [detailArray count];
//server tidak konsisten,parameter totalpages di menu ini tidak ada (menu lain ada) -_-!
if (detailCount>=25) {
if ([jsonHeader objectForKey:#"totalRows"]) {
totalPages = [[jsonHeader objectForKey:#"totalRows"] floatValue]/25;
}else{
//buat unlimited
totalPages = 9999;
}
}
}
//orientation handling
- (void)canRotate{}
- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification{
NSLog(#"orientation change...");
[self adjustViewsForOrientation:[[UIDevice currentDevice] orientation]];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
NSLog(#"orientation:%d",orientation);
if (orientation == UIInterfaceOrientationPortrait)
// if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
landscape = NO;
//harus di tambahin ini karena parentnya uiviewcontroller bukan uitableviewcontroller jadi tidak otomatis
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, 320, 480);
[self.tableView layoutSubviews];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[self.tableView reloadData];
//load the portrait view
NSLog(#"portraid");
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[self.navigationController.navigationBar setHidden:NO];
}
// else if (orientation == UIInterfaceOrientationLandscapeLeft)
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
landscape = YES;
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
//harus di tambahin ini karena parentnya uiviewcontroller bukan uitableviewcontroller jadi tidak otomatis
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, 480, 320);
[self.tableView layoutSubviews];
[self.tableView reloadData];
//load the landscape view
NSLog(#"landscape");
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[self.navigationController.navigationBar setHidden:NO];
}
}
in .h
#import <UIKit/UIKit.h>
#interface SecuritiesInstructionsResultViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>{
NSDictionary *jsonHeader;
//untuk paging
NSInteger currentPage;
Boolean *isReloading;
NSInteger totalRows;
float totalPages;
BOOL landscape;
BOOL isScrollingEnable;
}
#property (strong, nonatomic) IBOutlet UITableView *tableView;
//#property NSMutableArray *rowData;
#property NSMutableArray *dataAccount;
#property NSMutableArray *dataCashAmount;
#property NSMutableArray *dataCode;
#property NSMutableArray *dataDate;
#property NSMutableArray *dataExtRef;
#property NSMutableArray *dataInsType;
#property NSMutableArray *dataSecuritiesAmmount;
#property NSMutableArray *dataStatus;
#property NSString *dateFrom;
#property NSString *dateTo;
#property NSDictionary *jsonResult;
#property NSString *selectedAccount;
#property NSString *selectedSecurityCode;
#property NSString *selectedSecuritySecCodeType;
#property NSString *selectedSecurityType;
#property NSString *selectedCurrencyCode;
#property NSString *selectedStatus;
#property NSString *selectedDate;
#property NSString *selectedToDate;
#end
i've prevent to not called scrollviewdidscroll method when back button pressed by implementing viewWillDisappear, but it doesn't help. the app is still crash and no error message.
Any one have a clue for this problem?
Set delegate of UIScrollView or inherited classes (UITableView, UICollectionView and etc) to nil
Objective-C:
- (void)dealloc {
[scrollView setDelegate:nil];
}
Swift:
deinit {
scrollView.delegate = nil
}
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];