添加多语言
This commit is contained in:
@@ -7,10 +7,12 @@
|
||||
|
||||
#import "HomeVC.h"
|
||||
#import "KBGuideVC.h"
|
||||
#import "KBLangTestVC.h"
|
||||
|
||||
@interface HomeVC ()
|
||||
@property (nonatomic, strong) UITextView *textView;
|
||||
|
||||
@interface HomeVC () <UITableViewDelegate, UITableViewDataSource>
|
||||
@property (nonatomic, strong) UITextView *textView; // 作为表头,保持原有键盘测试
|
||||
@property (nonatomic, strong) UITableView *tableView; // 首页列表
|
||||
@property (nonatomic, copy) NSArray<NSString *> *items; // 简单数据源
|
||||
@end
|
||||
|
||||
@implementation HomeVC
|
||||
@@ -18,14 +20,32 @@
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
CGRect frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 200)/2, 150, 200, 200);
|
||||
|
||||
// 表头中的文本输入框:保留原有键盘测试能力
|
||||
CGFloat width = [UIScreen mainScreen].bounds.size.width;
|
||||
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 220)];
|
||||
CGRect frame = CGRectMake(16, 16, width - 32, 188);
|
||||
self.textView = [[UITextView alloc] initWithFrame:frame];
|
||||
self.textView.text = @"测试";
|
||||
self.textView.text = KBLocalized(@"home_input_placeholder");
|
||||
self.textView.layer.borderColor = [UIColor blackColor].CGColor;
|
||||
self.textView.layer.borderWidth = 0.5;
|
||||
[self.view addSubview:self.textView];
|
||||
[self.textView becomeFirstResponder];
|
||||
|
||||
[header addSubview:self.textView];
|
||||
|
||||
// 列表
|
||||
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleInsetGrouped];
|
||||
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.tableView.delegate = self;
|
||||
self.tableView.dataSource = self;
|
||||
self.tableView.tableHeaderView = header;
|
||||
[self.view addSubview:self.tableView];
|
||||
|
||||
// 数据
|
||||
self.items = @[ KBLocalized(@"home_item_lang_test") ];
|
||||
|
||||
// 首次进入,聚焦到输入框方便测试键盘
|
||||
dispatch_async(dispatch_get_main_queue(), ^{ [self.textView becomeFirstResponder]; });
|
||||
|
||||
// 可选:示例网络请求(保持原逻辑)
|
||||
[[KBNetworkManager shared] GET:@"app/config" parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
NSLog(@"====");
|
||||
}];
|
||||
@@ -33,7 +53,11 @@
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated{
|
||||
[super viewWillAppear:animated];
|
||||
NSLog(@"===");
|
||||
// 刷新本页涉及的多语言文案
|
||||
self.title = KBLocalized(@"home_title");
|
||||
// 重建 items 以更新本地化的 cell 标题
|
||||
self.items = @[ KBLocalized(@"home_item_lang_test") ];
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
||||
@@ -44,6 +68,28 @@
|
||||
// [KBHUD showAllowTapToDismiss:true];
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDataSource
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.items.count; }
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
static NSString *cellId = @"home.cell";
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
||||
if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; }
|
||||
cell.textLabel.text = self.items[indexPath.row];
|
||||
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||||
return cell;
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDelegate
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
if (indexPath.row == 0) {
|
||||
// 多语言测试页
|
||||
KBLangTestVC *vc = [KBLangTestVC new];
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#pragma mark - Navigation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user