2014-05-09 7 views
1

Je développe une application sencha tactile et l'utilisation de PhoneGap pour construire ios. Je souhaite afficher une barre d'outils numérique sur le clavier ios et obtenir l'action du bouton numérique dans textField. Je peux montrer la barre d'outils au-dessus du clavier mais je ne peux pas mettre à jour les valeurs de textFild selon le bouton tap/clik.Voici mon code .Veuillez m'aider à résoudre ce problème. J'ai fait le code dans MainViewController.m. Je ne suis pas familier avec l'objectif c.Sencha Touch, Phonegap, IOS, clavier barre d'outils

#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 

Répondre

1

Enfin, j'ai obtenu la sortie.

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