UITableView

  表视图(UITableView)继承自UIScrollView,它有两个协议:UITableViewDelegate委托协议和UITableViewDataSource数据源协议。UITableViewCell类是单元格类,UITableViewController类是UITableView的控制器,UITableViewHeaderFooterView类用于为节点和节脚提供视图,它是iOS6之后才有的新类

表视图的分类

  普通表视图:主要用于动态表,而动态表一般在单元格数目未知的情况下使用。

  分组表视图:一般用于静态表,会将表分成很多“孤岛”,这个“孤岛”由一些类似的单元格组成。静态表一般用于控件的界面布局,它是iOS5之后又故事板提供的。

单元格的组成和样式

  单元格由图标、标题和扩展视图等组成

单元格有很多样式,可根据需要进行选择。图标、标题和副标题可以有选择地设置,扩展视图可以内置或自定义,其中内置的扩展视图是在枚举类型UITableViewCellAccessoryType中定义的。

typedef NS_ENUM(NSInteger, UITableViewCellAccessoryType) {

    UITableViewCellAccessoryNone,                   //没有扩展图标

    UITableViewCellAccessoryDisclosureIndicator,    //扩展指示,触摸该图标>将切换到下一级表视图

    UITableViewCellAccessoryDetailDisclosureButton, //细节展示按钮,触摸该单元格的时候,表视图会以视图的方式显示当前但严格的更多详细信息

    UITableViewCellAccessoryCheckmark,              // 选择标志,表示该行被选中

    UITableViewCellAccessoryDetailButton NS_ENUM_AVAILABLE_IOS(7_0) // info button. tracks

};

iOS API提供的单元格样式是放在枚举类型UITableViewCellStyle中定义的,而UITableViewCellStyle枚举类型中定义的常量如下:

typedef NS_ENUM(NSInteger, UITableViewCellStyle) {

    UITableViewCellStyleDefault, //默认样式,只有图标和主标题

    UITableViewCellStyleValue1, //无图标,带副标题样式1, Left aligned label on left and right aligned label on right with blue text (Used in Settings)

    UITableViewCellStyleValue2, //无图标,带副标题样式2, Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)

    UITableViewCellStyleSubtitle //带有副标题的样式,有图标、主标题和副标题

};

 

数据源协议和委托协议:UITableViewDataSource和UITableViewDelegate

数据源:

NSBundle *bundle = [NSBundle mainBundle];

NSString *plistPath = [bundle pathForResource:@"team"  ofType:@"plist"];

self.listTeams = [[NSArray alloc] initWithContentsOfFile:plistPath];

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [self.listTeams count];

    

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    NSUInteger row = [indexPath row];

    NSDictionary  *rowDict = [self.listTeams objectAtIndex:row];

    cell.textLabel.text = [rowDict objectForKey:@"name"];

    

    NSString *imagePath = [rowDict objectForKey:@"image"];

    imagePath = [imagePath stringByAppendingString:@".png"];

    cell.imageView.image = [UIImage imageNamed:imagePath];

    

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;   

}

 可自定义Cell;

添加搜索栏

 

UISearchBarDelegate是搜索栏控件的委托协议,UISearchDisplayController用来管理搜索栏并显示搜索结果视图。事件处理由UISearchDisplayDelegate协议的委托对象来管理

在搜索栏中输入查询条件,会触发UISearchBarDelegate委托对象的searchBar:textDidChange:方法和UISearchDisplayDelegate委托对象的searchDisplayController:shouldReloadTableForSearchString:方法,我们实现其一就可以达到搜索的目的。

-(void)filterContentForSearchText:(NSString *)searchText scope:(NSUInteger)scope

{

    if ([searchText length] == 0) {

        self.listFilterTeams = [NSMutableArray arrayWithArray:self.listTeams];

    }

    NSPredicate *scopePredicate;

    NSArray *tempArray;

    switch (scope) {

        case 0:

            scopePredicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",searchText];

            tempArray = [self.listTeams filteredArrayUsingPredicate:scopePredicate];

            self.listFilterTeams = [NSMutableArray arrayWithArray:tempArray];

            break;

        case 1:

            scopePredicate = [NSPredicate predicateWithFormat:@"SELF.image contains[c] %@",searchText];

            tempArray = [self.listTeams filteredArrayUsingPredicate:scopePredicate];

            self.listFilterTeams = [NSMutableArray arrayWithArray:tempArray];

            break;

            

        default:

            self.listFilterTeams = [NSMutableArray arrayWithArray:self.listTeams];

            break;

    }

}

 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString

{

    [self filterContentForSearchText:searchString scope:self.searchBar.selectedScopeButtonIndex];

    return YES;

}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

{

    [self filterContentForSearchText:@"" scope:-1];

}

 

分节表视图 

 1.添加索引

  使用原则:

索引标题不能与显示的标题完全一样:如果与要显示的标题一致,索引就变得毫无意义

索引标题应具有代表性,能代表一个数据集合。

分节是添加索引的前提。

如果采用了索引列表视图,一般情况下就不再使用扩展视图

-(NSArray*) sectionIndexTitlesForTableView:(UITableView*)tableView 中返回索引值

 

 

分组和静态表实例:

 

  

转载于:https://www.cnblogs.com/PJXWang/p/5428784.html

考虑柔性负荷的综合能源系统低碳经济优化调度【考虑碳交易机制】(Matlab代码实现)内容概要:本文围绕“考虑柔性负荷的综合能源系统低碳经济优化调度”展开,重点研究在碳交易机制下如何实现综合能源系统的低碳化与经济性协同优化。通过构建包含风电、光伏、储能、柔性负荷等多种能源形式的系统模型,结合碳交易成本与能源调度成本,提出优化调度策略,以降低碳排放并提升系统运行经济性。文中采用Matlab进行仿真代码实现,验证了所提模型在平衡能源供需、平抑可再生能源波动、引导柔性负荷参与调度等方面的有效性,为低碳能源系统的设计与运行提供了技术支撑。; 适合人群:具备一定电力系统、能源系统背景,熟悉Matlab编程,从事能源优化、低碳调度、综合能源系统等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究碳交易机制对综合能源系统调度决策的影响;②实现柔性负荷在削峰填谷、促进可再生能源消纳中的作用;③掌握基于Matlab的能源系统建模与优化求解方法;④为实际综合能源项目提供低碳经济调度方案参考。; 阅读建议:建议读者结合Matlab代码深入理解模型构建与求解过程,重点关注目标函数设计、约束条件设置及碳交易成本的量化方式,可进一步扩展至多能互补、需求响应等场景进行二次开发与仿真验证。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值