-
Notifications
You must be signed in to change notification settings - Fork 570
Expand file tree
/
Copy pathViewController.m
More file actions
164 lines (121 loc) · 5.38 KB
/
Copy pathViewController.m
File metadata and controls
164 lines (121 loc) · 5.38 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
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
//
// ViewController.m
// TYAttributedLabelDemo
//
// Created by tanyang on 15/4/8.
// Copyright (c) 2015年 tanyang. All rights reserved.
//
#import "ViewController.h"
#import "SimpleTextViewController.h"
#import "AttributedTextViewController.h"
#import "ImageTextViewController.h"
#import "LinkTextViewController.h"
#import "AutoLayoutLinkImageTextViewController.h"
#import "ParseTextViewController.h"
#import "AddViewTextViewController.h"
#import "TextContainerViewController.h"
#import "TextTableViewController.h"
#import "AutoLayoutTableViewController.h"
#import "LabelXibViewController.h"
#import "TextViewController.h"
@interface tableViewItem : NSObject
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *detailText;
@property (nonatomic, assign) Class destVcClass;
@end
@implementation tableViewItem
@end
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, weak) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *itemArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
[self addTableView];
[self addTableItems];
[self.tableView reloadData];
}
- (NSMutableArray *)itemArray
{
if (_itemArray == nil) {
_itemArray = [NSMutableArray array];
}
return _itemArray;
}
- (void)addTableView
{
// 添加tableView
UITableView *tableView = [[UITableView alloc]init];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
self.tableView = tableView;
}
- (void)viewWillLayoutSubviews
{
self.tableView.frame = self.view.bounds;
}
- (void)addTableItems
{
[self addTableItemWithTitle:@"SimpleText" detailText:@"简单文本显示" destVcClass:[SimpleTextViewController class]];
[self addTableItemWithTitle:@"XibLabelText" detailText:@"简单文本显示(xib)" destVcClass:[LabelXibViewController class]];
[self addTableItemWithTitle:@"AttributedText" detailText:@"属性文本显示" destVcClass:[AttributedTextViewController class]];
[self addTableItemWithTitle:@"LinkText" detailText:@"属性链接文本显示" destVcClass:[LinkTextViewController class]];
[self addTableItemWithTitle:@"AutoLayoutLinkText" detailText:@"AutoLayout属性链接文本显示" destVcClass:[AutoLayoutLinkImageTextViewController class]];
[self addTableItemWithTitle:@"ImageText" detailText:@"属性文本和Image(URL)混排显示" destVcClass:[ImageTextViewController class]];
[self addTableItemWithTitle:@"AddViewText" detailText:@"属性文本和UIView混排显示" destVcClass:[AddViewTextViewController class]];
[self addTableItemWithTitle:@"TextContainer" detailText:@"文本容器提前生成" destVcClass:[TextContainerViewController class]];
[self addTableItemWithTitle:@"ParseText" detailText:@"自定义排版解析图文混排显示" destVcClass:[ParseTextViewController class]];
[self addTableItemWithTitle:@"AttributedTextCell" detailText:@"tableViewCell显示图文混排" destVcClass:[TextTableViewController class]];
[self addTableItemWithTitle:@"AutoLayoutAttributedTextCell" detailText:@"Autolayout tableViewCell显示图文混排" destVcClass:[AutoLayoutTableViewController class]];
[self addTableItemWithTitle:@"TextViewController" detailText:@"TextViewController_My" destVcClass:[TextViewController class]];
}
- (void)addTableItemWithTitle:(NSString *)title detailText:(NSString *)detailText destVcClass:(Class)destVcClass
{
tableViewItem *item = [[tableViewItem alloc]init];
item.title = title;
item.detailText = detailText;
item.destVcClass = destVcClass;
[self.itemArray addObject:item];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.itemArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
tableViewItem *item = self.itemArray[indexPath.row];
cell.textLabel.text = item.title;
cell.detailTextLabel.text = item.detailText;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == self.itemArray.count -1) {
[self.navigationController pushViewController:[[TextViewController alloc] initWithNibName:@"TextViewController" bundle:nil] animated:YES];
return;
}
tableViewItem *item = self.itemArray[indexPath.row];
if (item.destVcClass ) {
UIViewController *vc = [[item.destVcClass alloc]init];
vc.view.backgroundColor = [UIColor whiteColor];
vc.title = item.title;
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end