【代码笔记】iOS-提醒时间的选择

来源:互联网 发布:java并发编程的书 编辑:程序博客网 时间:2024/05/16 12:32

一,效果图。

二,工程图。

三,代码。

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.}
复制代码

 

0 0