0

我正在尝试从应用程序从 url 获取的 plist 加载自定义键盘上的按钮之一。我无法在键盘加载时加载 plist 数组,因此它可以在键盘视图加载时读取文本。

//
//  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];



}
4

0 回答 0