美文网首页
分段控制器

分段控制器

作者: JaneEyre3X | 来源:发表于2018-08-20 17:15 被阅读0次

在此之前在 AppDelegate.m 中设置导航才可以完成效果


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//添加导航控制器

self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[ViewController new]];

return YES;

}

// 这个我们的ViewController 在这里实现主要功能

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

{

UITableView * table;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.title = @"小优";

self.view.backgroundColor = [UIColor grayColor];

NSArray *array = [NSArray arrayWithObjects:@"唐装",@"男装",@"php",@"金溪",@"java",@"e语言", nil];

//初始化UISegmentedControl

UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];

segment.tintColor = [UIColor whiteColor];

//设置frame

segment.frame = CGRectMake(0, 65, 340, 30);

//添加到视图

[self.view addSubview:segment];

UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(340, 65, 60, 30)];

[but setTitle:@"+" forState:UIControlStateNormal];

but.backgroundColor = [UIColor whiteColor];

[but addTarget:self action:@selector(dianji:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:but];

}

-(void)dianji:(UIButton *)btn

{

UIView * vieww = [[UIView alloc]initWithFrame:CGRectMake(260, 100, 60, 150)];

vieww.backgroundColor = [UIColor whiteColor];

[self.view addSubview:vieww];

table =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150) style:UITableViewStyleGrouped];

table.delegate = self;

table.dataSource = self;

[vieww addSubview:table];

}

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

{

return 3;

}

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

{

static NSString * cellID = @"cell";

UITableViewCell * cell =[table dequeueReusableCellWithIdentifier:cellID];

if (!cell)

{

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

}

if (indexPath.row == 0)

{

cell.textLabel.text = @"添加";

}

if (indexPath.row == 1)

{

cell.textLabel.text = @"确认";

}

if (indexPath.row == 2)

{

cell.textLabel.text = @"关闭";

}

return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

return 2;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

if (indexPath.row == 0)

{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认添加" message:@"操作已完成" preferredStyle:  UIAlertControllerStyleAlert];

[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//点击按钮的响应事件;

}]];

//弹出提示框;

[self presentViewController:alert animated:true completion:nil];

}

}

还请书友们 给个评价 让小编知道自己的不足~~谢过啦

相关文章

  • UIControl

    UIControl 控制类 主要学习了分段控制器、滑块控制器、页码控制器、开关、步进控制器 一、分段控制器UISe...

  • 第二周第二天 开关,分段控制器

    1,开关2,分段控制器 设置选中第几个分段控制器 设置方法 开关的关闭状态 设置方法

  • 发现简书iOS版本一个bug

    首先进入文章分段控制器页,然后点击动态分段控制器按钮,在scrollview左移瞬间下拉,bug出现。

  • 月下乔安

    //初始化分段控制器 -(UISegmentedControl * )segment { if(!_segme...

  • 分段控制器

    在此之前在 AppDelegate.m 中设置导航才可以完成效果 // 这个我们的ViewController 在...

  • iOS分段控制器 - UISegmentedControl

    简单的分段控制器 实现在导航条上

  • iOS 自定义分段控制器

    最近做项目时遇到一些问题,就是项目里原有分段控制器的适用范围有些局限,虽然网上也有很多分段控制器的demo,但自己...

  • ios 分段控制器

    手动导入第三方SCNavTabBar 导入头文件#import "SCNavTabBarController.h"...

  • IOS分段控制器

    首先在AppDelegate.m中修改根视图AppDelegate.m中 ViewController.m中 新建...

  • UISegmentControl 分段控制器

    链接地址:http://blog.csdn.net/guigen_l/article/details/72855603

网友评论

      本文标题:分段控制器

      本文链接:https://www.haomeiwen.com/subject/twbliftx.html