forked from wfxiaolong/STWebViewController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableViewController.m
More file actions
94 lines (75 loc) · 3.14 KB
/
TableViewController.m
File metadata and controls
94 lines (75 loc) · 3.14 KB
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
//
// TableViewController.m
// STWebViewController
//
// Created by linxiaolong on 15/5/15.
// Copyright (c) 2015年 linxiaolong. All rights reserved.
//
#import "TableViewController.h"
#import "STAlertView.h"
#import "PPWebViewController.h"
#import "NSEtcHosts.h"
@interface TableViewController ()
@property (nonatomic, strong) NSMutableArray *hostArray;
@property (nonatomic, strong) NSMutableArray *ipAddreddArray;
@property (nonatomic, strong) STAlertView *stCusAlertView;
@end
static NSString *identify = @"tableViewCellIdentify";
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self configureData];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightBarClick:)];
self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)configureData {
self.hostArray = @[].mutableCopy;
self.hostArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"hostArray"];
self.ipAddreddArray = @[].mutableCopy;
self.ipAddreddArray =[[NSUserDefaults standardUserDefaults] objectForKey:@"ipAddressArray"];
if (!self.hostArray || !self.ipAddreddArray) {
self.hostArray = @[@"www.duobao_admin.com"].mutableCopy;
self.ipAddreddArray = @[@"120.132.59.160"].mutableCopy;
}
}
- (void)rightBarClick:(id)sender {
if (!self.stCusAlertView) {
self.stCusAlertView = [[STAlertView alloc] init];
}
[self.stCusAlertView mainTitle:@"添加" block:^(NSString *host, NSString *ipAddress) {
[STAlertView hideAlertViewWithAnimation:YES];
if ([host isEqualToString:@""] || [ipAddress isEqualToString:@""]) {
return ;
}
[self.hostArray addObject:host];
[self.ipAddreddArray addObject:ipAddress];
[self.tableView reloadData];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.hostArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identify];
cell.textLabel.text = self.hostArray[indexPath.row];
cell.detailTextLabel.text = self.ipAddreddArray[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[NSEtcHosts addHost:self.hostArray[indexPath.row] ipAddress:self.ipAddreddArray[indexPath.row]];
/// HTTPS的需要自己判断
NSString *urlSting = [@"http://" stringByAppendingString:self.hostArray[indexPath.row]];
PPWebViewController *webView = [[PPWebViewController alloc] initWithURL:[NSURL URLWithString:urlSting]];
[self.navigationController pushViewController:webView animated:YES];
}
@end