热更新demo

searchTableViewController.m 4.2KB

    // // searchTableViewController.m // ThePaperBase // // Created by Huixin on 15/7/27. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "searchTableViewController.h" #import "searchCell.h" @interface searchTableViewController () @property(nonatomic, strong)NSMutableArray *cellHeightList; @property(nonatomic, strong)NSArray* strList; @end @implementation searchTableViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor clearColor]; self.tableView.clipsToBounds = YES; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self configCanRefresh:NO canLoad:YES]; [self needNoFirstAutoRefresh]; } - (void)setDataList:(NSArray *)list { _dataList = list; self.cellHeightList = [NSMutableArray array]; for (int i =0 ; i < _dataList.count; i++) { listContObjectVO *listBo = _dataList[i]; CGFloat titleHeight = returnTextHeightWithRTLabel(listBo.name, self.view.frame.size.width-20, appFont(TEXT_THREE_LEVELSIZE, NO), 7); [_cellHeightList addObject:@(titleHeight+36)]; } [self.tableView reloadData]; } - (void)setSearchStr:(NSString *)searchStr { _searchStr = searchStr; _strList = [searchStr componentsSeparatedByRegex:@"\\s+"]; } #pragma mark - TPtableview delegate - (void)pullLoadMoreHander { if (isBlankString(self.nextUrl)) { [self loadFailed]; return; } NSString *url = [self.nextUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [Remote doJsonAction:2 requestUrl:url parameter:nil delegate:self]; } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 2) { NSMutableArray *oldSearchList = [NSMutableArray arrayWithArray:self.dataList]; NSMutableArray *newSearchList = [NSMutableArray array]; NSArray *list = responsData[@"searchList"]; [list enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { listContObjectVO *listBo = setJsonDicToDataModel(obj, [listContObjectVO class]); [newSearchList addObject:listBo]; }]; [oldSearchList addObjectsFromArray:newSearchList]; self.dataList = oldSearchList; NSString *url = responsData[@"nextUrl"]; [self loadSuccess]; self.nextUrl = url; } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code { ShowTextMessage(message); [self loadFailed]; } #pragma mark - tableview - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataList.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [_cellHeightList[indexPath.row] floatValue]; } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *searchCellID = @"searchCell"; searchCell *cell = (searchCell*)[tableView dequeueReusableCellWithIdentifier:searchCellID]; if (nil == cell) { cell = [[searchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchCellID]; } listContObjectVO *listBo = _dataList[indexPath.row]; [cell setData:listBo key:_strList]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; if ([self.delegate respondsToSelector:@selector(searchGoToContent:)]) { listContObjectVO *listBo = _dataList[indexPath.row]; [self.delegate searchGoToContent:listBo]; } } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end