手机设置界面UItableView

//  AppDelegate.m

//首先创建一个导航栏

ViewController *vc = [[ViewController alloc] init];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

self.window.rootViewController = nav;



// 自己创建的类 MyView.h  继承 UIView

- (void)setImageView:(UIImage *)image textFieldTitle:(NSString *)Title detailTextField:(NSString *)detail;


//  MyView.m

- (void)setImageView:(UIImage *)image textFieldTitle:(NSString *)Title detailTextField:(NSString *)detail

{

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

imageView.frame = CGRectMake(0, 0, 44, 44);

[self addSubview:imageView];

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, self.frame.size.width / 2 - 25, 44)];

titleLabel.text = Title;

[self addSubview:titleLabel];

UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 + 25, 0, self.frame.size.width/2 - 25, 44)];

detailLabel.text = detail;

[self addSubview:detailLabel];

}


//  ViewController.m

<UITableViewDataSource, UITableViewDelegate>

//属性 可变数组

@property (nonatomic, strong) NSMutableArray *array;

@implementation ViewController

{

NSArray *netArray;

NSArray *notArray;

NSArray *ordArray;

}

//====================================================

netArray = @[@"飞行模式",@"无线局域网",@"蓝牙",@"蜂窝移动网络"];

notArray = @[@"通知",@"控制中心",@"勿扰模式"];

ordArray = @[@"通用",@"显示与亮度",@"墙纸",@"声音",@"Siri",@"Touch ID与密码",@"电池"];

self.array = [NSMutableArray arrayWithObjects:netArray,notArray,ordArray, nil];

// UITableView // 表格

// 初始化

// Frame:尺寸位置

// style:枚举的两种样式

UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];

// UITabelView通过代理的方式实现

//  签订代理

tableView.delegate  = self;

tableView.dataSource = self;

[self.view addSubview:tableView];

// 行高

// 默认高度 44

tableView.rowHeight = 50;

// 分割线

//    tableView.separatorColor = [UIColor redColor];

//    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

//===================================================

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return self.array.count;

}

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

{

// 第一个必须实现的方法

// TableView显示的行数

return [self.array[section] count];

}

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

{

// 每行显示的内容

// 命名一个重用池

static NSString *reuse = @"reuse";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];

// 如果重用池取出失败, 那么创建一个加入进去

if (cell == nil)

{

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];

}

cell.imageView.image = [UIImage imageNamed:@"2.jpg"];

// 数组套数组

// indexPath.section 取出对应section(分组)中的数组

// indexPath.row 从section数组中取出对应的String

NSArray *array = self.array[indexPath.section];

NSString *string = [array objectAtIndex:indexPath.row];

cell.textLabel.text = string;

return cell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return self.array.count;

}

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

{

// 第一个必须实现的方法

// TableView显示的行数

return [self.array[section] count];

}

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

{

// 每行显示的内容

// 命名一个重用池

static NSString *reuse = @"reuse";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];

// 如果重用池取出失败, 那么创建一个加入进去

if (cell == nil)

{

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];

}

cell.imageView.image = [UIImage imageNamed:@"2.jpg"];

// 数组套数组

// indexPath.section 取出对应section(分组)中的数组

// indexPath.row 从section数组中取出对应的String

NSArray *array = self.array[indexPath.section];

NSString *string = [array objectAtIndex:indexPath.row];

cell.textLabel.text = string;

return cell;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,090评论 3 38
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,453评论 9 5
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 2,919评论 2 10
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,547评论 1 14
  • 在我年龄尚轻,阅历尚浅的那些年,我孤芳自赏,我桀骜不驯,我玩世不恭,我亦目中无人。随着时间的推移,我渐渐的领...
    艾薇儿_0c3d阅读 266评论 0 0