Ios UIInputViewController赢得';t从plist加载数组
我正在尝试从应用程序从url获取的plist加载自定义键盘上的一个按钮。我无法在键盘加载时加载plist数组,因此它可以在键盘视图加载时读取文本Ios UIInputViewController赢得';t从plist加载数组,ios,objective-c,uiinputviewcontroller,Ios,Objective C,Uiinputviewcontroller,我正在尝试从应用程序从url获取的plist加载自定义键盘上的一个按钮。我无法在键盘加载时加载plist数组,因此它可以在键盘视图加载时读取文本 // // KeyboardViewController.h // MyKeyboard #import <UIKit/UIKit.h> @interface KeyboardViewController : UIInputViewController{ NSMutableArray *keyboardArray; } @en
//
// 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];
}
//
//KeyboardViewController.h
//我的键盘
#进口
@接口键盘视图控制器:UIInputViewController{
NSMUTABLEARRY*键盘阵列;
}
@结束
//
//KeyboardViewController.m
//我的键盘
#导入“KeyboardViewController.h”
#导入“Keyboard.h”
@接口KeyboardViewController()
@属性(强,非原子)键盘*键盘;
@结束
@键盘视图控制器的实现
-(无效)updateViewConstraints{
[super updateViewConstraints];
//在此处添加自定义视图大小限制
}
-(无效)视图将显示:(BOOL)动画{
}
-(无效)viewDidLoad{
[超级视图下载];
//加载键盘类型
NSString*键盘名称;
键盘名称=@“键盘”;
self.keyboard=[[NSBundle mainBundle]loadNibNamed:keyboardName所有者:nil选项:nil]objectAtIndex:0];
[自填式斯托克板];
self.inputView=self.keyboard;
//在此处执行自定义UI设置
[自我挫折];
}
-(无效)缩进按钮{
//设置键标签的文本
//从所有山脉的Plist文档创建数组
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
NSString*documentsDirectory=[paths objectAtIndex:0];
NSString*plistPath=[DocumentsDirectoryStringByAppendingPathComponent:@“databaseOfHills.plist”];
keyboardArray=[[NSMutableArray alloc]initWithContentsOfFile:plistPath]mutableCopy];
//设置键标签的文本
UIButton*btn=(UIButton*)[self.view视图带标记:1];
NSString*selectedStringFromPlist=[[keyboardArray objectAtIndex:0]objectForKey:@“Button1”];
[btn setTitle:selectedStringFromPlist for状态:UIControlStateNormal];
}
粘贴您尝试过的内容和遇到的问题。。。。确切地在setButtonsMethod中,如果使用常规字符串命名按钮标签,则效果良好。从数组加载字符串不起作用。我还尝试从NSUserdefaults加载数据并删除plist,但这也不起作用。键盘扩展是否可能无法访问应用程序包?如果您需要更多的代码或信息,请提供建议,我将很乐意发布。谢谢你的帮助。