1,创建模型:用来保存数据
创建模型:用来保存数据
模型.h文件
@interface CKUser : NSObject
//重写构造方法
-(instancetype)initWith:(NSString*)username name:(NSString*)name;
/*
* 名字
*/
@property (assign, readwrite, nonatomic) NSString *name;
@property (assign, readwrite, nonatomic) NSString *username;
@end
模型.m文件
@implementation CKUser
-(instancetype)initWith:(NSString*)username name:(NSString*)name {
self = [super init];
self.username = username;
self.name = name;
return self;
}
@end
根控制器设置UITableViewController的控制器
#import "ViewController.h"
#import "CKUser.h"
@interface ViewController ()
//数据保存的模型数组
@property (nonatomic, strong) NSMutableArray *userArray;
//分组的数组
@property (nonatomic, strong) NSMutableArray *sectionsArray;
//UITableView索引搜索工具类
@property (nonatomic, strong) UILocalizedIndexedCollation *collation;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//创建对象
// self.collation = [UILocalizedIndexedCollation currentCollation];
//拿到列表 A - Z 在加一个 # 一共 27个
// NSArray *temp = [self.collation sectionTitles];
// NSLog(@"%@",temp);
[self configureSections];
}
#define NEW_USER(str) [[CKUser alloc] initWith:str name:str]
//配置分组信息
- (void)configureSections {