File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010#import " KtMainTableViewCell.h"
1111#import " KtMainTableViewDataSource.h"
1212
13+ #import " AFNetworking.h"
14+ #import " KtTableViewBaseItem.h"
15+
1316@interface KTMainViewController ()
1417
1518
1619@end
1720
21+ static NSString * const BaseURLString = @" http://1.footballapp.sinaapp.com/mooclist.php" ;
22+
1823@implementation KTMainViewController
1924
2025- (void )viewDidLoad {
2126 [super viewDidLoad ];
27+ NSDictionary *parameters = @{@" nextPage" : @" 0" };
28+ AFHTTPSessionManager *manager = [AFHTTPSessionManager manager ];
29+ manager.responseSerializer .acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject: @" text/html" ];
30+ NSURLSessionDataTask *task = [manager GET: BaseURLString parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
31+ NSDictionary *dic = (NSDictionary *)responseObject;
32+ NSArray *array = dic[@" data" ];
33+ for (NSDictionary *dict in array) {
34+ KtTableViewBaseItem *item = [[KtTableViewBaseItem alloc ] initWithImage: nil Title: dict[@" title" ] SubTitle: nil AccessoryImage: nil ];
35+ [self .dataSource appendItem: item];
36+ }
37+ [self .tableView reloadData ];
38+ } failure: ^(NSURLSessionTask *operation, NSError *error) {
39+ NSLog (@" Error: %@ " , error);
40+ }];
2241 // Do any additional setup after loading the view, typically from a nib.
2342}
2443
Original file line number Diff line number Diff line change 2424
2525@property (nonatomic , strong ) NSMutableArray *sections; // 二维数组,每个元素都是一个 SectionObject
2626
27+ - (void )appendItem : (KtTableViewBaseItem *)item ;
28+
2729@end
Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ - (Class)tableView:(UITableView*)tableView cellClassForObject:(KtTableViewBaseIt
3030 return [KtBaseTableViewCell class ];
3131}
3232
33+ - (void )appendItem : (KtTableViewBaseItem *)item {
34+ KtTableViewSectionObject *firstSectionObject = [self .sections objectAtIndex: 0 ];
35+ [firstSectionObject.items addObject: item];
36+ }
37+
3338#pragma mark - UITableViewDataSource Required
3439- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
3540 if (self.sections .count > section) {
You can’t perform that action at this time.
0 commit comments