用table分组写设置界面

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView ;
@property (nonatomic,strong)NSArray *dataArray ;

@property (nonatomic,strong) UIView *footView;

@end

@implementation ViewController

- (NSArray *)dataArray
{
    if (nil == _dataArray) {
        _dataArray = @[
                       @[@"个人资料",@"账号绑定"],
                       @[@"收货地址管理",@"实名认证管理",@"购物偏好设置"] ,
                       @[@"新消息设置"],
                       @[@"修改密码"],
                       @[@"清理缓存",@"关于聚美",@"日志上传"],
                       ];
    }
    
    return _dataArray ;
}

-(UIView *)footView{
    if (_footView == nil) {
        _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,0,self.view.frame.size.height*0.3)];
        _footView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
        
    }
    
    return _footView;
}

#pragma mark - getter/setter
- (UITableView *)tableView
{
    if (nil == _tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
        //_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        //_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];
        _tableView.dataSource = self ;
        _tableView.delegate = self ;
        _tableView.showsVerticalScrollIndicator=NO;//关闭上下滑动时的滑条
        self.tableView.tableFooterView = self.footView;
    }
    
    return _tableView ;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
    
    UIView *theView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];
    theView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:theView];
    
    UILabel *theLabel=[[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4, 30, self.view.frame.size.width/2, 40)];
    theLabel.text=@"设置";
    theLabel.textAlignment=NSTextAlignmentCenter;
    theLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/30];
    [theView addSubview:theLabel];
    
    
    NSLog(@"viewDidLoad");
    
    [self.view addSubview:self.tableView] ;
    
    UIButton *footButton=[[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/5, self.view.frame.size.height/25, self.view.frame.size.width*3/5, 16+self.view.frame.size.height/32)];
    footButton.backgroundColor=[UIColor whiteColor];
    [footButton setTitle:@"退出登录" forState:UIControlStateNormal];
    [footButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [footButton addTarget:self action:@selector(footButtonClick) forControlEvents:UIControlEventTouchUpInside];
    footButton.titleLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/45];
    //切圆角和设置弧度
    footButton.layer.cornerRadius = footButton.frame.size.height/2;//半径大小
    footButton.layer.masksToBounds = YES;//是否切割
    [self.footView addSubview:footButton];
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count ;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataArray[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
    cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.text = self.dataArray[indexPath.section][indexPath.row];
    cell.textLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/45];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//点击cell时,cell的颜色不改变
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//每个cell的后面出现>
    
    
    return cell ;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 20+self.view.frame.size.height/28;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSString *theStr;
    
    switch (indexPath.section) {
        case 0:
            
            if (indexPath.row==0) {
                NSLog(@"点击了个人资料");
                theStr=@"个人资料";
            } else if (indexPath.row==1) {
                NSLog(@"账号绑定");
                theStr=@"账号绑定";
            }
            
            break ;
        case 1:
            
            if (indexPath.row==0) {
                NSLog(@"点击了收货地址管理");
                theStr=@"收货地址管理";
            } else if (indexPath.row==1) {
                NSLog(@"点击了实名认证管理");
                theStr=@"实名认证管理";
            } else if (indexPath.row==2) {
                NSLog(@"点击了购物偏好设置");
                theStr=@"购物偏好设置";
            }
            
            break ;
        case 2:
            
            if (indexPath.row==0) {
                NSLog(@"点击了新消息设置");
                theStr=@"新消息设置";
            }
            
            break ;
        case 3:
            
            if (indexPath.row==0) {
                NSLog(@"点击了修改密码");
                theStr=@"修改密码";
            }
            
            break ;
        case 4:
            
            if (indexPath.row==0) {
                NSLog(@"点击了清理缓存");
                theStr=@"清理缓存";
            } else if (indexPath.row==1) {
                NSLog(@"点击了关于聚美");
                theStr=@"关于聚美";
            } else if (indexPath.row==2) {
                NSLog(@"点击了日志上传");
                theStr=@"日志上传";
            }
            
            break ;
        default: break;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UILabel *theLabel=[[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-self.view.frame.size.width/3)/2, self.view.frame.size.height/2, self.view.frame.size.width/3, 20+self.view.frame.size.height/35)];
        theLabel.backgroundColor=[UIColor blackColor];
        theLabel.layer.cornerRadius = theLabel.frame.size.height/7;
        theLabel.clipsToBounds = YES;
        theLabel.textColor=[UIColor whiteColor];
        theLabel.alpha=0.8f;
        theLabel.textAlignment=NSTextAlignmentCenter;
        theLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/40];
        theLabel.text=theStr;
        [self.view addSubview:theLabel];
        
        //设置动画
        CATransition *transion=[CATransition animation];
        transion.type=@"push";//动画方式
        transion.subtype=@"fromTop";//设置动画从哪个方向开始
        [theLabel.layer addAnimation:transion forKey:nil];//给layer添加动画。设置延时效果
        //不占用主线程
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
            
            [theLabel removeFromSuperview];
            
        });//这句话的意思是1.5秒后,把label移出视图
    });
    
    
}

//下面是设置分组的头部和底部间距

//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return self.view.frame.size.width/35;//section头部高度
}

//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        //设置头部颜色
        UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
        headerView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
        
        return headerView ;
}

//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    
    return 0;//section底部高度
            
}

//section底部视图- (UIView
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
            
    UIView *viewdd=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
    viewdd.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
    
    return viewdd;
}

-(void)footButtonClick
{
    NSLog(@"点击了退出登录按钮");
    NSLog(@"ddd~~");
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UILabel *theLabel=[[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-self.view.frame.size.width/3)/2, self.view.frame.size.height/2, self.view.frame.size.width/3, 20+self.view.frame.size.height/35)];
        theLabel.backgroundColor=[UIColor blackColor];
        theLabel.layer.cornerRadius = theLabel.frame.size.height/7;
        theLabel.clipsToBounds = YES;
        theLabel.textColor=[UIColor whiteColor];
        theLabel.alpha=0.8f;
        theLabel.textAlignment=NSTextAlignmentCenter;
        theLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/40];
        theLabel.text=@"退出登录";
        [self.view addSubview:theLabel];
        
        //设置动画
        CATransition *transion=[CATransition animation];
        transion.type=@"push";//动画方式
        transion.subtype=@"fromTop";//设置动画从哪个方向开始
        [theLabel.layer addAnimation:transion forKey:nil];//给layer添加动画。设置延时效果
        //不占用主线程
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
            
            [theLabel removeFromSuperview];
            
        });//这句话的意思是1.5秒后,把label移出视图
    });
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 

@end

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的实现: ```python import tkinter as tk from tkinter import filedialog import pandas as pd root = tk.Tk() root.title("Excel处理工具") # 选择文件 def choose_file(): file_path = filedialog.askopenfilename() file_path_entry.delete(0, tk.END) file_path_entry.insert(tk.END, file_path) # 合并文件 def merge_files(): file_path = file_path_entry.get() if not file_path: tk.messagebox.showerror("错误", "请选择要合并的文件") return merged_data = pd.DataFrame() data = pd.read_excel(file_path) merged_data = merged_data.append(data, ignore_index=True) data_table.delete(*data_table.get_children()) for i, row in merged_data.iterrows(): data_table.insert("", tk.END, values=[row["名称"], row["数量"], row["价格"]]) # 分组统计 def group_and_count(): selected_items = data_table.selection() if len(selected_items) == 0: tk.messagebox.showerror("错误", "请选择要统计的数据") return data = [] for item in selected_items: name, count, price = data_table.item(item)["values"] data.append({"名称": name, "数量": count, "价格": price}) grouped_data = pd.DataFrame(data).groupby("名称").agg({"数量": "sum", "价格": "mean"}).reset_index() result_table.delete(*result_table.get_children()) for i, row in grouped_data.iterrows(): result_table.insert("", tk.END, values=[row["名称"], row["数量"], row["价格"]]) # 文件路径输入框和按钮 file_path_label = tk.Label(root, text="文件路径") file_path_label.pack(pady=10) file_path_entry = tk.Entry(root, width=50) file_path_entry.pack() choose_file_btn = tk.Button(root, text="选择文件", command=choose_file) choose_file_btn.pack(pady=10) # 数据表格 data_table_label = tk.Label(root, text="数据") data_table_label.pack(pady=10) data_table = tk.ttk.Treeview(root, columns=["name", "count", "price"], show="headings") data_table.heading("name", text="名称") data_table.heading("count", text="数量") data_table.heading("price", text="价格") data_table.pack() # 合并按钮 merge_btn = tk.Button(root, text="合并", command=merge_files) merge_btn.pack(pady=10) # 分组统计按钮 group_btn = tk.Button(root, text="分组统计", command=group_and_count) group_btn.pack(pady=10) # 分组统计结果表格 result_table_label = tk.Label(root, text="统计结果") result_table_label.pack(pady=10) result_table = tk.ttk.Treeview(root, columns=["name", "count", "price"], show="headings") result_table.heading("name", text="名称") result_table.heading("count", text="数量") result_table.heading("price", text="平均价格") result_table.pack() root.mainloop() ``` 这个程序使用了 Python 的 Tkinter 库来实现 GUI 界面,使用 Pandas 库来读取和处理 Excel 文件。用户可以通过点击“选择文件”按钮选择要处理的 Excel 文件,然后点击“合并”按钮进行合并,合并后的数据会显示在数据表格中。用户可以在数据表格中选择要统计的数据,然后点击“分组统计”按钮进行统计,统计结果会显示在统计结果表格中。注意,这个程序只支持处理包含“名称”、“数量”、“价格”三列数据的 Excel 文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值