zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-提醒时间的选择

    一,效果图。

    二,工程图。

    三,代码。

    RootViewController.h

    复制代码
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    <UITableViewDataSource,UITableViewDelegate>
    {
        UITableView *remindTable;
        int lastIndex;
        int nowIndex;
        NSArray *textArray;
    }
    
    
    @end
    复制代码

     

    RootViewController.m

    复制代码
    #import "RootViewController.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        self.title=@"提醒时间";
        
        //UITableView
        remindTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 1, 320, self.view.bounds.size.height)];
        [remindTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [remindTable setScrollEnabled:YES];
        [remindTable setDataSource:self];
        [remindTable setDelegate:self];
        [self.view addSubview:remindTable];
        
    }
    #pragma  -mark -UITableView Delegate
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 9;
    }
    - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        
        textArray = [[NSArray alloc]initWithObjects:@"无",@"5分钟前",@"15分钟",@"30分钟前",@"1小时前",@"两小时前",@"1天前",@"2天前",@"事件发生日",nil];
        cell.textLabel.text = [textArray objectAtIndex:indexPath.row];
        cell.textLabel.textColor = [UIColor orangeColor];
        
        //分割线
        UIImage *line = [UIImage imageNamed:@"line.png"];
        UIImageView *lineView = [[UIImageView alloc]initWithFrame:CGRectMake(5,cell.contentView.frame.size.height-1 , 310, 1)];
        [lineView setImage:line];
        [cell.contentView addSubview:lineView];
        
        //勾的图片
        UIImage *check = [UIImage imageNamed:@"gou.png"];
        UIImageView *checkView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, check.size.width/2, check.size.height/2)];
        [checkView setImage:check];
        if (indexPath.row == nowIndex) {
            cell.accessoryView = checkView;
        }
        else if (indexPath.row == lastIndex){
            cell.accessoryView = UITableViewCellAccessoryNone;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        lastIndex = nowIndex;
        nowIndex = (int)indexPath.row;
        
        NSLog(@"====%d",nowIndex);
        NSLog(@"----%d",lastIndex);
        [remindTable reloadData];
    }
    
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    复制代码

     

  • 相关阅读:
    正则表达式
    [创业指南]给海归技术创业兄弟的九个忠告
    about avast
    设计模式Hibernate
    job desc
    把INT转换成2进制等
    微服务调用跟踪
    Redis 分布式锁实现
    jquery中的$.ajax()方法
    订单从ftp写入到b2b
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5282098.html
Copyright © 2011-2022 走看看