0

I am trying to have one of the buttons on my custom keyboard load from a plist that the app fetches from a url. I cannot get the plist array to load when the keyboard loads so it can read the text when the keyboard view loads.

//
//  KeyboardViewController.h
//  MyKeyboard

#import <UIKit/UIKit.h>

@interface KeyboardViewController : UIInputViewController{

NSMutableArray *keyboardArray;

}

@end

//
//  KeyboardViewController.m
//  MyKeyboard



#import "KeyboardViewController.h"
#import "Keyboard.h"
@interface KeyboardViewController ()

@property (strong,nonatomic)Keyboard *keyboard;

@end

@implementation KeyboardViewController

- (void)updateViewConstraints {
[super updateViewConstraints];

// Add custom view sizing constraints here
}

-(void)viewWillAppear:(BOOL)animated{


}


- (void)viewDidLoad {
[super viewDidLoad];

//Load Keyboard Type
NSString *keyboardName;
keyboardName = @"Keyboard";


self.keyboard = [[[NSBundle mainBundle] loadNibNamed:keyboardName owner:nil     options:nil] objectAtIndex:0];
[self addGesturesToKeyboard];

self.inputView = self.keyboard;

// Perform custom UI setup here


[self setButtons];

}

-(void)setButtons{

//Sets Text of KEY Label

//create array from Plist document of all mountains
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory =  [paths objectAtIndex:0];
NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"databaseOfHills.plist"];
keyboardArray = [[[NSMutableArray alloc] initWithContentsOfFile:plistPath]mutableCopy];

//Sets Text of KEY Label

UIButton *btn = (UIButton*)[self.view viewWithTag:1];

NSString *selectedStringFromPlist = [[keyboardArray     objectAtIndex:0]objectForKey:@"Button1"];

[btn setTitle:selectedStringFromPlist forState:UIControlStateNormal];



}
peko
  • 11,267
  • 4
  • 33
  • 48
Jason P.
  • 399
  • 1
  • 11
  • Paste what have you tried and where you got stuck.... exactly..! – bhargavg Sep 02 '14 at 14:34
  • In the setButtonsMethod, if I use a regular string to name the button label it works fine. Loading the string from the array does not work. I also tried loading the data from NSUserdefaults and removing the plist, but that does not work either. Is it possible that the keyboard extension does not have access to the app bundle? If you need more code or information please advise and I will happily post it. Thank you for your help. – Jason P. Sep 02 '14 at 14:47

0 Answers0