forked from iimgal/StudyiOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageTableViewController.m
More file actions
99 lines (76 loc) · 2.86 KB
/
Copy pathImageTableViewController.m
File metadata and controls
99 lines (76 loc) · 2.86 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
//
// ImageTableViewController.m
// StudyiOS
//
// Created by on 11-11-4.
// Copyright (c) 2011年 ZhangYiCheng. All rights reserved.
//
#import "ImageTableViewController.h"
#import "AsyncImageView.h"
@implementation ImageTableViewController
@synthesize list;
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// 增加Code按钮,可跳转至教学页面
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Code" style:UIBarButtonItemStyleBordered target:self action:@selector(code)];
self.navigationItem.rightBarButtonItem = item;
NSMutableArray *array = [[NSMutableArray alloc]
initWithObjects:@"http://i.6.cn/cvbnm/98/70/47/f40590f07d9901e9106636259686fde7.jpg",
@"http://face.weiphone.com/data/avatar/002/29/85/69_avatar_middle.jpg",
nil];
self.list = array;
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
#pragma mark - Table view data source
- (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 [self.list count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSInteger row = [indexPath row];
NSString *imgurl = [self.list objectAtIndex:row];
NSURL *url = [NSURL URLWithString:imgurl];
AsyncImageView *oldImg = (AsyncImageView *)[cell.contentView viewWithTag:999];
[oldImg removeFromSuperview];
CGRect frame = CGRectMake(0, 0, 44, 44);
// 创建异步图片视图
AsyncImageView* asyncImage = [[AsyncImageView alloc] initWithFrame:frame];
asyncImage.tag =999;
// 加载异步图片
[asyncImage loadImageFromURL:url];
[cell.contentView addSubview:asyncImage];
NSLog(@"图片地址:%@",imgurl);
return cell;
}
// 跳转至教学页面
- (void)code
{
CodeViewController *controller = [[CodeViewController alloc] initWithNibName:@"CodeViewController" bundle:nil];
NSString *name = [NSString stringWithUTF8String:object_getClassName(self)];
controller.className = name;
[self.navigationController pushViewController:controller animated:YES];
}
@end