| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // SiteTableViewController.m
- // Haishenghai-master
- //
- // Created by GG on 2019/1/25.
- // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "SiteTableViewController.h"
- #import "PlaceModel.h"
- #import "SitTabCell.h"
- static NSString *const cellID = @"cellID";
- @interface SiteTableViewController ()
- {
- //左边被选中的索引值
- NSInteger _selectIndex;
-
- }
- /*数据源*/
- @property(nonatomic,strong)NSMutableArray *dataArray;
- @end
- @implementation SiteTableViewController
- - (void)viewWillAppear:(BOOL)animated {
-
- [super viewWillAppear:animated];
- //选中第一个
- [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_selectIndex inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
- //
- [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) {
-
- NSLog(@"%@----array",array);
- _dataArray = array;
-
- [self.tableView reloadData];
-
- }];
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- self.tableView.showsHorizontalScrollIndicator =NO;
- self.tableView.showsVerticalScrollIndicator = NO;
- [self.tableView registerClass:[SitTabCell class] forCellReuseIdentifier:cellID];
- self.tableView.backgroundColor = [UIColor colorWithRed:224/255.0 green:224/255.0 blue:224/255.0 alpha:1];
- // _dataArray=[[NSMutableArray alloc]init];
- _selectIndex =0;
- [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) {
-
- NSLog(@"%@----array",array);
- _dataArray = array;
- if (_dataArray.count != 0) {
- PlaceModel *model = _dataArray[0];
- NSLog(@"--------%@",model.Id);
- NSArray *infoArr = @[model.Id,model.location];
- NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:infoArr,@"siteID", nil];
- [[NSNotificationCenter defaultCenter]postNotificationName:@"ChangeSiteID" object:nil userInfo:dic];
- }
- [self.tableView reloadData];
-
- }];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Table view data source
- //- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- // return 1;
- //}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return _dataArray.count;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 54;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 44;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- SitTabCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
- //让单元格的分割线和Cell一样宽
- cell.preservesSuperviewLayoutMargins = false;
- cell.separatorInset = UIEdgeInsetsZero;
- cell.layoutMargins = UIEdgeInsetsZero;
- cell.model = self.dataArray[indexPath.row];
- cell.botlabel.textColor = SXUIColorFromRGB(0x444444);
- cell.botlabel.numberOfLines = 2;
- cell.botlabel.font = [UIFont systemFontOfSize:18];
- //设置selectedBackgroundView
- cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
-
- cell.selectedBackgroundView.backgroundColor = [UIColor orangeColor];
-
- //textLabel的选中状态
-
- cell.textLabel.highlightedTextColor = [UIColor whiteColor];
-
- // 另外需要默认指定第一行时,可在添加
-
- if (indexPath.row==_selectIndex) {//指定第一行为选中状态
-
- [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
-
- }
- cell.backgroundColor = [UIColor whiteColor];
-
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- _selectIndex = indexPath.row;
-
- //点击的时候传值
- PlaceModel *model = self.dataArray[_selectIndex];
-
- [DataSourceManager getDeveceWithUrlPagesize:100 SiteId:model.Id Page:1 completionBlock:^(NSMutableArray *array) {
-
- NSLog(@"zheshi1%@",array);
- if (self.delegate && [self.delegate respondsToSelector:@selector(siteViewContller:didSelectRowWithData:)]) {
- [self.delegate siteViewContller:self didSelectRowWithData:array];
-
- }
- NSDictionary *dic =[NSDictionary dictionaryWithObjectsAndKeys:model.location,@"location", nil];
- [[NSNotificationCenter defaultCenter]postNotificationName:@"location" object:nil userInfo:dic];
- }];
-
-
-
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- UIView *headerView = [[UIView alloc]init];
- headerView.backgroundColor = [UIColor grayColor];
- UILabel *siteLabel = [[UILabel alloc]init];
- siteLabel.frame = CGRectMake(0, 0, self.tableView.frame.size.width, 44);
- siteLabel.text = @"场所列表";
- siteLabel.font = [UIFont systemFontOfSize:18];
- siteLabel.textColor = [UIColor whiteColor];
- siteLabel.textAlignment = NSTextAlignmentCenter;
- [headerView addSubview:siteLabel];
- return headerView;
- }
- - (void)setDelegate:(id<SiteTableViewControllerDelegate>)delegate {
-
- _delegate = delegate;
- /*
- 1:默认表格的某一行被选中,不会调用didSelectRowAtIndexPath方法,只是设置cell的选中的一个状态
- 2:获得tableView选中的某一行的indexpath:self.tableView.indexPathForSelectedRow
- // */
- // [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
- //
- }
- /*
- 1:两方法分别是:视图即将出现的时候调用,视图已经出现的时候调用
- 2:当某个控制器被压入栈里,或是被moda的控制器遮住的时候,返回到此控制器,则两个方法依然会被调用
- */
- @end
|