热更新demo

topicSearchListViewController.m 4.6KB

    // // TopicSearchListViewController.m // ThePaperBase // // Created by Huixin on 15/8/11. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicSearchListViewController.h" #import "topicSearchCell.h" @interface topicSearchListViewController () @property(nonatomic, strong)NSMutableArray *cellHeightList; @end @implementation topicSearchListViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [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++) { TopicInfoBO *topic = _dataList[i]; CGFloat titleHeight = returnTextHeightWithRTLabel(topic.title, self.view.frame.size.width-60, appFont(TEXT_THREE_LEVELSIZE, NO), 7); //bug5145: 话题搜索,ios8和ios9各有显示不完的现象 [_cellHeightList addObject:@(titleHeight+74)]; } [self.tableView reloadData]; } #pragma mark - TPTableViewController delegate - (void)pullLoadMoreHander{ if (isBlankString(self.nextUrl)) { //TPLOG(@"数据有问题,无法获取新数据"); [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) { TopicInfoBO *topic = setJsonDicToDataModel(obj, [TopicInfoBO class]); [newSearchList addObject:topic]; }]; [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 - uitableView - (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 = @"topicSearchCell"; topicSearchCell *cell = (topicSearchCell*)[tableView dequeueReusableCellWithIdentifier:searchCellID]; if (nil == cell) { cell = [[topicSearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchCellID]; } TopicInfoBO *topic = _dataList[indexPath.row]; [cell setData:topic key:_searchStr]; 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:)]) { TopicInfoBO *topic = _dataList[indexPath.row]; [self.delegate searchGoToContent:topic]; } } - (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. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end