看了几个实例,最终解决了这个问题,之间为什么老是有问题没有解决呢,原因我觉得是跟ARC有关,因为我的应用是使用ARC的然后将下载回来的代码进行了调整,将release的代码段去掉了。结果有了一些问题,也不是很了解具体是哪里。目前问题解决了,里面使用了关于ARC机制和非ARC机制共存的办法,详细的内容可以参考我的这篇文章iOS 开发,工程中混合使用 ARC 和非ARC

代码段贴一下好了:

EGOTableViewPullRefresh的下载地址:http://vdisk.weibo.com/s/FtH88

indexViewController.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// indexViewController.h
// index
//
// Created by david on 13-6-8.
// Copyright (c) 2013年 walkerfree. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "EGORefreshTableHeaderView.h"

@interface indexViewController : UIViewController<UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, EGORefreshTableHeaderDelegate>
{
EGORefreshTableHeaderView *_refreshHeaderView;
BOOL _reloading;
}
@property (strong, nonatomic) IBOutlet UISearchBar *personSearch;
@property (strong, nonatomic) IBOutlet UITableView *dataTable;
@property (strong, nonatomic) NSMutableDictionary *dataDic;

-(void) initPersonIndexListData;
@end

indexViewController.m

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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//
// indexViewController.m
// index
//
// Created by david on 13-6-8.
// Copyright (c) 2013年 walkerfree. All rights reserved.
//

#import "indexViewController.h"
#import "personIndexTrendViewController.h"
#import "listCell.h"

@interface indexViewController ()

@end

@implementation indexViewController

@synthesize personSearch = _personSearch;
@synthesize dataTable = _dataTable;
@synthesize dataDic = _dataDic;

- (void)viewDidLoad
{
[super viewDidLoad];
[self initPersonIndexListData];
self.dataTable.delegate = self;
self.dataTable.dataSource = self;

if (_refreshHeaderView == nil) {
//初始化下拉刷新控件
_refreshHeaderView = [[EGORefreshTableHeaderView alloc] init];
_refreshHeaderView.delegate = self;
//将下拉刷新控件作为子控件添加到UITableView中
[self.dataTable addSubview:_refreshHeaderView];
}


[_refreshHeaderView refreshLastUpdatedDate];

}

-(void) startLoadingTableViewData
{
[self initPersonIndexListData];
_reloading = YES;
}

-(void) endLoadingTableViewData
{
_reloading = NO;
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.dataTable];
// NSLog(@"done");
}

#pragma mark -
#pragma mark UIScrollViewDelegate Methods
-(void) scrollViewDidScroll:(UIScrollView *)scrollView
{
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
}

-(void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}

#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods
-(void) egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view
{
[self startLoadingTableViewData];
[self performSelector:@selector(endLoadingTableViewData) withObject:nil afterDelay:3.0];
}

-(BOOL) egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView *)view
{
return _reloading;
}

-(NSDate *)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView *)view
{
return [NSDate date];
}



-(void) viewWillDisappear:(BOOL)animated
{
UIBarButtonItem *returnBarItem = [[UIBarButtonItem alloc] init];
returnBarItem.title = @"返回";
self.navigationItem.backBarButtonItem = returnBarItem;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma UITableView
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataDic count];
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *listCellIdentifier = @"listCell";

UINib *nib = [UINib nibWithNibName:@"listCell" bundle:nil];
[self.dataTable registerNib:nib forCellReuseIdentifier:listCellIdentifier];

listCell *cell = [tableView dequeueReusableCellWithIdentifier:listCellIdentifier];
if(cell == nil){
cell = [[listCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:listCellIdentifier];

}

NSDictionary *dic = [self.dataDic objectForKey:[NSString stringWithFormat:@"%d",[indexPath row]]];

cell.personRank.text = [NSString stringWithFormat:@"%d",[indexPath row] + 1];
cell.personName.text = [dic valueForKey:@"zh_name"];
cell.personIndex.text = [NSString stringWithFormat:@"艺人新媒体指数 %0.2f",[[dic valueForKey:@"score"] floatValue]];
cell.personIndex.font = [UIFont systemFontOfSize:14.0];
cell.personIndex.textColor = [UIColor lightGrayColor];

if([[NSString stringWithFormat:@"%u",[indexPath row]] isEqualToString:@"0"])
{
cell.personRank.backgroundColor = [UIColor greenColor];
}
else
{
cell.personRank.backgroundColor = [UIColor lightGrayColor];
}

if([[NSString stringWithFormat:@"%u",[indexPath row]] isEqualToString:@"1"])
{
cell.personRank.backgroundColor = [UIColor greenColor];
}

if([[NSString stringWithFormat:@"%u",[indexPath row]] isEqualToString:@"2"])
{
cell.personRank.backgroundColor = [UIColor greenColor];
}



cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dic = [self.dataDic valueForKey:[NSString stringWithFormat:@"%u",[indexPath row]]];
personIndexTrendViewController *trend = [[personIndexTrendViewController alloc] initWithNibName:@"personIndexTrendViewController"
bundle:nil];
trend.personInfo = [dic mutableCopy];
[self.navigationController pushViewController:trend animated:YES];

}

#pragma UISearchBar


#pragma 自定义函数
-(void)initPersonIndexListData
{
NSLog(@"加载数据");
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSDate *date = [NSDate date];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSString *dateString = [dateFormatter stringFromDate: [NSDate dateWithTimeInterval:-(2 * 24 * 60 * 60) sinceDate:date]];

NSString *urlString = @"http://XXXXXXXXX.XXX.XXX.XXX?";

NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60];

NSURLResponse *response = [[NSURLResponse alloc] init];
NSError *receiveDataError = [[NSError alloc] init];

NSMutableData *receivedData = (NSMutableData *)[NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&receiveDataError];

if(receivedData == nil)
{
NSLog(@"获取数据失败");
}
else
{
NSError *jsonError = [[NSError alloc] init];
NSDictionary *personDictionary = [NSJSONSerialization JSONObjectWithData:receivedData
options:NSJSONReadingMutableContainers
error:&jsonError];
NSMutableDictionary *personInfo = [personDictionary objectForKey:@"data"];

NSMutableDictionary *personList = [personInfo objectForKey:@"list"];

self.dataDic = [NSMutableDictionary dictionaryWithCapacity:20];

if([personList isKindOfClass:[NSMutableArray class]])
{
int i = 0;
for (NSDictionary *dic in personList) {
[self.dataDic setObject:dic forKey:[NSString stringWithFormat:@"%d",i]];
i++;
}
}



if([personList isKindOfClass:[NSMutableDictionary class]])
{
NSLog(@"NSMutableDictionary 类");
}

if([self.dataDic count] > 0)
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
}
}
@end