日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

UITableView的UITableViewStyleGrouped

發布時間:2024/9/5 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UITableView的UITableViewStyleGrouped 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

UITableView的UITableViewStyleGrouped

以下圖例就是分組UITableViewStyleGrouped的樣式

本人提供快速集成的方法,不弄臟你那雙手:)

源碼:

TableViewData.h

// // TableVewData.h // Sections // // Copyright (c) 2014年 Y.X. All rights reserved. // #import <Foundation/Foundation.h>@interface TableViewData : NSObject// 添加數據源 + 數據源標簽 - (void)addDataArray:(NSArray *)array arrayFlag:(NSString *)flag;// 對應區域中的row的個數 - (NSInteger)numberOfRowsInSection:(NSInteger)section;// 有幾個section - (NSInteger)numberOfSections;// 對應于Section上的flag值標簽 - (NSString *)flagInSection:(NSInteger)section;// 對應于indexPath中的數據 - (id)dataInIndexPath:(NSIndexPath *)indexPath;@end

TableViewData.m

// // TableVewData.m // Sections // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "TableViewData.h"@interface TableViewData ()@property (nonatomic, strong) NSMutableArray *dataArray; @property (nonatomic, strong) NSMutableArray *nameList;@end@implementation TableViewData- (instancetype)init {self = [super init];if (self){_dataArray = [NSMutableArray new];_nameList = [NSMutableArray new];}return self; }- (void)addDataArray:(NSArray *)array arrayFlag:(NSString *)flag {[_dataArray addObject:array];[_nameList addObject:flag]; }- (NSInteger)numberOfRowsInSection:(NSInteger)section {return [_dataArray[section] count]; }- (NSInteger)numberOfSections {return [_dataArray count]; }- (NSString *)flagInSection:(NSInteger)section {return _nameList[section]; }- (id)dataInIndexPath:(NSIndexPath *)indexPath {return _dataArray[indexPath.section][indexPath.row]; }@end

使用情況:

// // RootViewController.m // UITableViewGroup // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "RootViewController.h" #import "TableViewData.h"static NSString *reusedFlag = @"reusedFlag";@interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>@property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) TableViewData *tableViewData;@end@implementation RootViewController- (void)viewDidLoad {[super viewDidLoad];// 初始化tableView(分組形勢的tableView)_tableView = [[UITableView alloc] initWithFrame:self.view.boundsstyle:UITableViewStyleGrouped];_tableView.delegate = self;_tableView.dataSource = self;[self.view addSubview:_tableView];// tableView數據_tableViewData = [TableViewData new];[_tableViewData addDataArray:@[@"1", @"2", @"3"] arrayFlag:@"設置"]; // section1[_tableViewData addDataArray:@[@"", @"", @""] arrayFlag:@"配置"]; // section2[_tableViewData addDataArray:@[@"one", @"two", @"three"] arrayFlag:@"閑置"]; // section3 }// 每個區多少個cell - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return [_tableViewData numberOfRowsInSection:section]; }// 創建cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusedFlag];if (cell == nil){cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:reusedFlag];}// section1if ([[_tableViewData flagInSection:indexPath.section] isEqualToString:@"設置"]){NSString *str = [_tableViewData dataInIndexPath:indexPath];cell.textLabel.text = str;cell.textLabel.textColor = [UIColor redColor];}// section2if ([[_tableViewData flagInSection:indexPath.section] isEqualToString:@"配置"]){NSString *str = [_tableViewData dataInIndexPath:indexPath];cell.textLabel.text = str;cell.textLabel.textColor = [UIColor blueColor];}// section3if ([[_tableViewData flagInSection:indexPath.section] isEqualToString:@"閑置"]){NSString *str = [_tableViewData dataInIndexPath:indexPath];cell.textLabel.text = str;cell.textLabel.textColor = [UIColor magentaColor];}return cell; }// 多少個區 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return [_tableViewData numberOfSections]; }// 每個區的標題 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {return [_tableViewData flagInSection:section]; }@end

幾個需要注意的地方:

以下兩個方法是DataSource中的,直接與分組有關.

不同的section配置不同的標題.

看起來應該很直白:)

?

?

?

?

?

?

?

?

?

轉載于:https://www.cnblogs.com/YouXianMing/p/3944866.html

總結

以上是生活随笔為你收集整理的UITableView的UITableViewStyleGrouped的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。