EepromTemplateController.m
8.22キロバイト
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// EepromTemplateController.m
// jacket_test_ios
//
// Created by ドラッサル 亜嵐 on 2017/07/24.
// Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
//
#import "EepromTemplateController.h"
#import "EepromTemplateTableViewCell.h"
#import "DBManager.h"
@interface EepromTemplateController ()
@end
@implementation EepromTemplateController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated {
arrResult = [[NSMutableArray alloc] init];
UINib *nib = [UINib nibWithNibName:@"EepromTemplateTableViewCell" bundle:nil];
[tblResult registerNib:nib forCellReuseIdentifier:@"mycell"];
tblResult.delegate = self;
tblResult.dataSource = self;
[arrResult removeAllObjects];
NSArray *result = [[DBManager sharedInstance] getEepromTemplateData];
for(id key in result) {
NSString *valueRecordId = [key objectAtIndex:0];
NSString *valueRecordName = [key objectAtIndex:1];
NSString *valueDataId = [key objectAtIndex:2];
NSString *valueDataModel = [key objectAtIndex:3];
NSString *valueDataType = [key objectAtIndex:4];
NSString *valueDataOs = [key objectAtIndex:5];
NSString *valueDataPin = [key objectAtIndex:6];
NSMutableDictionary *newDict = [NSMutableDictionary dictionary];
[newDict setObject:valueRecordId forKey:@"recordId"];
[newDict setObject:valueRecordName forKey:@"recordName"];
[newDict setObject:valueDataId forKey:@"dataId"];
[newDict setObject:valueDataModel forKey:@"dataModel"];
[newDict setObject:valueDataType forKey:@"dataType"];
[newDict setObject:valueDataOs forKey:@"dataOs"];
[newDict setObject:valueDataPin forKey:@"dataPin"];
[arrResult addObject:newDict];
}
[tblResult reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)cancelButtonClicked:(id)sender {
[self dismissViewControllerAnimated:YES completion:Nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
NSDictionary *dataRecord = [arrResult objectAtIndex:row];
[self.delegate didChoose:[dataRecord valueForKey:@"recordId"]
recordName:[dataRecord valueForKey:@"recordName"]
dataId:[dataRecord valueForKey:@"dataId"]
dataModel:[dataRecord valueForKey:@"dataModel"]
dataType:[dataRecord valueForKey:@"dataType"]
dataOs:[dataRecord valueForKey:@"dataOs"]
dataPin:[dataRecord valueForKey:@"dataPin"]];
[self dismissViewControllerAnimated:YES completion:Nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [arrResult count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"mycell";
EepromTemplateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSInteger row = [indexPath row];
NSDictionary *dataRecord = [arrResult objectAtIndex:row];
// Configure the cell...
UIFont *newFont = [UIFont fontWithName:@"Arial" size:17.0];
cell.lblRecordName.font = newFont;
cell.lblRecordName.text = [dataRecord valueForKey:@"recordName"];
newFont = [UIFont fontWithName:@"Arial" size:12.0];
cell.lblRecordId.font = newFont;
cell.lblRecordId.text = [dataRecord valueForKey:@"recordId"];
cell.lblDataId.font = newFont;
cell.lblDataId.text = [dataRecord valueForKey:@"dataId"];
cell.lblDataModel.font = newFont;
cell.lblDataModel.text = [dataRecord valueForKey:@"dataModel"];
cell.lblDataType.font = newFont;
cell.lblDataType.text = [dataRecord valueForKey:@"dataType"];
cell.lblDataOs.font = newFont;
cell.lblDataOs.text = [dataRecord valueForKey:@"dataOs"];
cell.lblDataPin.font = newFont;
cell.lblDataPin.text = [dataRecord valueForKey:@"dataPin"];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @[
[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@"削除"
handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// own delete action
// Distructive button tapped.
NSLog(@"削除の確認");
NSDictionary * selectedData = [arrResult objectAtIndex:indexPath.row];
NSString *firmwareTitle = [selectedData valueForKey:@"file"];
UIAlertController *actionSheetConfirm = [UIAlertController alertControllerWithTitle:@"削除の確認" message:[NSString stringWithFormat:@"「%@」を削除します。よろしいですか?",firmwareTitle] preferredStyle:UIAlertControllerStyleAlert];
[actionSheetConfirm addAction:[UIAlertAction actionWithTitle:@"削除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *actionConfirm) {
// Get the record ID of the selected name and set it to the recordIDToEdit property.
NSDictionary * selectedData = [arrResult objectAtIndex:indexPath.row];
NSString *recordId = [selectedData valueForKey:@"recordId"];
NSLog(@"recordId = %@",recordId);
[[DBManager sharedInstance] deleteEepromTemplateData:recordId];
//[self populateDetail];
//[self.tblResult reloadData];
[arrResult removeObjectAtIndex:indexPath.row];
[tblResult deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}]];
[actionSheetConfirm addAction:[UIAlertAction actionWithTitle:@"キャンセル" style:UIAlertActionStyleDefault handler:^(UIAlertAction *actionConfirm) {
// Distructive button tapped.
NSLog(@"キャンセルの確認");
}]];
[self presentViewController:actionSheetConfirm animated:YES completion:nil];
}],
];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end