三级展开框的制作 未仔细测试有无bug

1. .m内容

#import "XLTableView.h"
#import "XLTableViewCell.h"
#import "PowerPictureViewController.h"

@interface XLTableView ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,UIAlertViewDelegate>

@property (nonatomic ,strong) NSMutableArray *Source_Array;

@property (nonatomic ,strong) NSMutableArray *redundant_Source_Array;

@property (nonatomic ,strong) NSMutableArray *remove_Data_Path_Array;

@property (nonatomic ,strong) NSMutableArray *redundant_Source_Array_total;

@property (nonatomic ,strong) NSMutableArray *remove_Data_Path_Array_total;

@property (nonatomic ,strong) NSArray *source_arr;

@property (nonatomic ,assign) NSInteger Path;

@property (nonatomic ,assign) NSInteger path_Path;

@property (nonatomic ,strong) NSString *The_first_layer_kay;//第一层键值

@property (nonatomic ,strong) NSString *The_second_floo_kay;//第二层键值

@property (nonatomic ,strong) NSString *The_third_layer_kay;//第三层键值

@end

@implementation XLTableView

- (instancetype)init_With_Frame:(CGRect)frame
                      with_Data:(NSArray *)Sourec_Array
            The_first_layer_kay:(NSString *)The_first_layer_kay
            The_second_floo_kay:(NSString *)The_second_floo_kay
            The_third_layer_kay:(NSString *)The_third_layer_kay
{
    self = [super initWithFrame:frame style:UITableViewStyleGrouped];

    if (self) {

        self.separatorStyle = UITableViewCellSeparatorStyleNone;

        [self registerNib:[UINib nibWithNibName:@"XLTableViewCell" bundle:nil]  forCellReuseIdentifier:@"XL_table_View_Cell"];

        self.path_Path = 0;

        self.dataSource = self;

        self.delegate = self;

        self.The_first_layer_kay = The_first_layer_kay;

        self.The_second_floo_kay = The_second_floo_kay;

        self.The_third_layer_kay = The_third_layer_kay;

        self.index_Path_Array = [NSMutableArray array];

        self.redundant_Source_Array = [NSMutableArray array];

        self.remove_Data_Path_Array = [NSMutableArray array];

        self.redundant_Source_Array_total = [NSMutableArray array];

        self.remove_Data_Path_Array_total = [NSMutableArray array];

        self.Source_Array = [self create_Temp_Data:Sourec_Array];

        self.all_Source_Array = [self Remove_all_levels:self.Source_Array];
    }
    return self;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    Header_View = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 45)];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                          action:@selector(tap:)];

    Header_View.backgroundColor = [UIColor whiteColor];

    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tianjia.png"]];

    image.frame = CGRectMake(0,0, 25, 25);

    image.center = Header_View.center;

    [Header_View addSubview:image];

    [Header_View addGestureRecognizer:tap];

    UILabel * lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, self.frame.size.width, 1)];

    lable.backgroundColor = [UIColor grayColor];

    [Header_View addSubview:lable];

    return Header_View;
}
-(void )tap:(UITapGestureRecognizer *)tap
{
    NSArray *other_Button_Titles = @[@"添加",@"修改"];
    if (!self.is) {
        other_Button_Titles = @[@"添加"];
    }
    [self createAlert_View_message:@"添加或修改"
                             Title:@"提示"
               cancel_Button_Title:@"取消"
               other_Button_Titles:other_Button_Titles
                         alert_Tag:AlertTag];
}
- (void)createAlert_View_message:(NSString *)message
                           Title:(NSString *)Title
             cancel_Button_Title:(NSString *)cancel_Button_Title
             other_Button_Titles:(NSArray *)other_Button_Titles
                       alert_Tag:(NSUInteger)tag
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:Title
                                                    message:message
                                                   delegate:self.vc
                                          cancelButtonTitle:cancel_Button_Title
                                          otherButtonTitles: nil];

    for (int32_t i = 0; i < other_Button_Titles.count; i++) {

        [alert addButtonWithTitle:other_Button_Titles[i]];
    }

    alert.tag = tag;

    [alert show];
}
- (void)createAlert_View_message:(NSString *)message
                           Title:(NSString *)Title
             cancel_Button_Title:(NSString *)cancel_Button_Title
             other_Button_Titles:(NSArray *)other_Button_Titles
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:Title
                                                    message:message
                                                   delegate:self
                                          cancelButtonTitle:cancel_Button_Title
                                          otherButtonTitles: nil];
    for (int32_t i = 0; i < other_Button_Titles.count; i++) {
        [alert addButtonWithTitle:other_Button_Titles[i]];
    }

    alert.tag = AlertTag;

    [alert show];
}
-(NSMutableArray *)create_Temp_Data:(NSArray *)Data{

    NSMutableArray *temp_Array = [NSMutableArray array];

    for (int i = 0; i < Data.count; i++) {

            [temp_Array addObject:Data[i]];

    }

    return temp_Array;
}

- (NSMutableArray *)Remove_all_levels:(NSMutableArray *)Source_Array
{
    NSMutableArray *all_Array = [NSMutableArray array];

    NSArray *The_first_layer_Array;

    NSArray *The_third_layer_Array;

    for (int32_t i = 0; i < Source_Array.count; i++) {

        NSArray *arr = @[@"1",@"1"];

        if (!self.The_first_layer_kay) {

            [all_Array addObject:Source_Array[i]];

        }else
        {
            [all_Array addObject:[Source_Array[i] objectForKey:self.The_first_layer_kay]];

            The_first_layer_Array = [[Source_Array[i] objectForKey:self.The_first_layer_kay] objectForKey:self.The_second_floo_kay];

            if (!The_first_layer_Array.count) {

                arr = @[@"1",@"222"];
            }
        }
        [self.index_Path_Array addObject:arr];

        for (int32_t j = 0; j < The_first_layer_Array.count; j ++) {

            NSArray *arr = @[@"2",@"1"];

            if (!self.The_first_layer_kay) {

                [all_Array addObject:The_first_layer_Array[j]];

                The_third_layer_Array = [The_first_layer_Array[j] objectForKey:self.The_third_layer_kay];

            }else
            {
                [all_Array addObject:The_first_layer_Array[j]];

                The_third_layer_Array = [The_first_layer_Array[j] objectForKey:self.The_third_layer_kay];

                if (!The_third_layer_Array.count) {

                    arr = @[@"2",@"222"];
                }
            }
            [self.index_Path_Array addObject:arr];

            for (int32_t l = 0; l < The_third_layer_Array.count; l++) {

                 NSArray *arr = @[@"3",@"222"];

                [self.index_Path_Array addObject:arr];

                [all_Array addObject:The_third_layer_Array[l]];
            }
        }
    }
    return all_Array;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.all_Source_Array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *indentifier = @"XL_table_View_Cell";

    static XLTableViewCell *cell = nil;

    cell = [tableView dequeueReusableCellWithIdentifier:indentifier];

    if (!cell) {

        cell = [[XLTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:indentifier];
    }
    cell.text_Label.text = [self table_View_Cell_Index_Path:indexPath];

    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 45;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self did_Select_Row_Index_Path:indexPath];
}
- (NSString *)table_View_Cell_Index_Path:(NSIndexPath *)indexPath
{
    NSString *Cell_string;

    NSArray *arr = self.index_Path_Array[indexPath.row];

    switch ([arr[0] intValue]) {
        case 1:
            Cell_string = [NSString stringWithFormat:@"%@",
                           [self.all_Source_Array[indexPath.row] objectForKey:@"name"]];
            break;
        case 2:
            Cell_string = [NSString stringWithFormat:@"       %@",
                           [self.all_Source_Array[indexPath.row] objectForKey:@"name"]];
            break;
        case 3:
           Cell_string = [NSString stringWithFormat:@"              %@",
                          [self.all_Source_Array[indexPath.row] objectForKey:@"name"]];
            break;
        default:
            break;
    }
    return Cell_string;
}
- (void)did_Select_Row_Index_Path:(NSIndexPath *)indexPath
{
    NSArray *arr;

    arr = self.index_Path_Array[indexPath.row];

    if (![arr[0] isEqualToString:@"3"]) {

        if ([arr[1] intValue] == 1){

            arr = @[arr[0],@"0"];

            [self.index_Path_Array replaceObjectAtIndex:indexPath.row
                                             withObject:arr];

            [self remove_data_View_Cell_data:indexPath
                                       Class:arr[0]];

        }else if ([arr[1] intValue] == 0) {

            arr = @[arr[0],@"1"];

            [self.index_Path_Array replaceObjectAtIndex:indexPath.row
                                             withObject:arr];

            [self add_table_view_cell_data:indexPath.row
                    redundant_Source_Array:self.redundant_Source_Array
                    remove_Data_Path_Array:self.remove_Data_Path_Array];

            [self cell_The_starting_position:indexPath.row
                                end_Position:self.redundant_Source_Array.count
                                     isState:YES];
        }
    }
}
- (void)add_table_view_cell_data:(NSInteger)indexPath_row
          redundant_Source_Array:(NSMutableArray *)redundant_Source_Array
          remove_Data_Path_Array:(NSMutableArray *)remove_Data_Path_Array
{
    for (int32_t i = 0; i < redundant_Source_Array.count; i++) {

        NSDictionary *dic = redundant_Source_Array[i];

        NSArray *Path_Dic = remove_Data_Path_Array[i];

        [self.all_Source_Array insertObject:dic
                                    atIndex:indexPath_row+1+i];

        [self.index_Path_Array insertObject:Path_Dic
                                    atIndex:indexPath_row+1+i];
    }
}
- (void)remove_data_View_Cell_data:(NSIndexPath *)indexPath
                             Class:(NSString *)string
{
    NSArray *source_arr1;

    source_arr1 = self.index_Path_Array[self.Path];

    if (self.redundant_Source_Array.count
        && self.Path != indexPath.row
        && [source_arr1[1] intValue] == 0
        && self.Path > indexPath.row) {

        source_arr1 = @[source_arr1[0],@"1"];

        [self.index_Path_Array replaceObjectAtIndex:self.Path
                                         withObject:source_arr1];

        [self add_table_view_cell_data:self.Path
                redundant_Source_Array:self.redundant_Source_Array
                remove_Data_Path_Array:self.remove_Data_Path_Array];

        [self cell_The_starting_position:self.Path
                            end_Position:self.redundant_Source_Array.count
                                 isState:YES];
    }
    if (self.redundant_Source_Array.count
        && self.Path != indexPath.row
        && [source_arr1[1] intValue] == 0
        && self.Path < indexPath.row) {

        for (int32_t i = 0; i < self.redundant_Source_Array.count; i++) {

            [self.redundant_Source_Array_total addObject:self.redundant_Source_Array[i]];

            [self.remove_Data_Path_Array_total addObject:self.remove_Data_Path_Array[i]];
        }
    }else if(self.Path > indexPath.row)
        self.path_Path = 0;

    [self.redundant_Source_Array removeAllObjects];

    [self.remove_Data_Path_Array removeAllObjects];

    for (int32_t i = (int32_t)indexPath.row+1; i < self.index_Path_Array.count; i++) {

        NSArray *arr = self.index_Path_Array[i];

        if ([arr[0] isEqualToString:string]) {
            break;
        }else if ([string isEqualToString:@"2"]) {

            if ([arr[0] isEqualToString:@"1"]) {
                break;
            }else {
                [self.redundant_Source_Array addObject:self.all_Source_Array[i]];
                [self.remove_Data_Path_Array addObject:self.index_Path_Array[i]];
            }
        }else {
            [self.redundant_Source_Array addObject:self.all_Source_Array[i]];
            [self.remove_Data_Path_Array addObject:self.index_Path_Array[i]];
        }
    }
    [self.all_Source_Array removeObjectsInRange:NSMakeRange(indexPath.row+1, self.redundant_Source_Array.count)];

    [self.index_Path_Array removeObjectsInRange:NSMakeRange(indexPath.row+1, self.remove_Data_Path_Array.count)];

    [self cell_The_starting_position:indexPath.row
                        end_Position:self.redundant_Source_Array.count
                             isState:NO];

    if (self.redundant_Source_Array_total.count) {

         source_arr1 = @[source_arr1[0],@"1"];

        [self.index_Path_Array replaceObjectAtIndex:self.Path withObject:source_arr1];

        [self add_table_view_cell_data:self.Path
                redundant_Source_Array:self.redundant_Source_Array_total
                remove_Data_Path_Array:self.remove_Data_Path_Array_total];

        [self cell_The_starting_position:self.Path
                            end_Position:self.redundant_Source_Array_total.count
                                 isState:YES];

        self.path_Path = self.redundant_Source_Array_total.count;

        [self.redundant_Source_Array_total removeAllObjects];

        [self.remove_Data_Path_Array_total removeAllObjects];
    }

    self.Path = indexPath.row + self.path_Path;
}
- (void)cell_The_starting_position:(NSInteger)start
                      end_Position:(NSInteger)termination
                           isState:(BOOL)state
{
    NSMutableArray *arr = [NSMutableArray array];

    for (NSInteger i = start+1; i <start+termination+1 ; i++) {

        NSIndexPath *index_path = [NSIndexPath indexPathForRow:i inSection:0];

        [arr addObject:index_path];
    }
    if (state) {
        [self insertRowsAtIndexPaths:arr
                    withRowAnimation:UITableViewRowAnimationNone];
    }else
        [self deleteRowsAtIndexPaths:arr
                    withRowAnimation:UITableViewRowAnimationNone];
}

@end

2. .h 内容

#import <UIKit/UIKit.h>

@protocol XLTableViewDelegate <NSObject>
@end

@interface XLTableView : UITableView
{
    UIView *Header_View;
}

- (instancetype)init_With_Frame:(CGRect)frame
                      with_Data:(NSArray *)Sourec_Array
            The_first_layer_kay:(NSString *)The_first_layer_kay
            The_second_floo_kay:(NSString *)The_second_floo_kay
            The_third_layer_kay:(NSString *)The_third_layer_kay;

@property (nonatomic ,strong) NSMutableArray *index_Path_Array;

@property (nonatomic ,strong) NSMutableArray *all_Source_Array;

@property (nonatomic ,strong) UIViewController *vc;

@property (nonatomic ,assign) BOOL is;

@end
时间: 2024-10-06 10:34:12

三级展开框的制作 未仔细测试有无bug的相关文章

圆角文本框的制作

把border:0px;outline:none;就可以清除边框.然后在外面放一个圆角div,文本框在div内居中的话能够,设置行高和text-align:center.或者也能够在背景图上放文本框.

单选复选框的制作

一.选择框 在使用表单设计调查表时,为了减少用户的操作,使用选择框是一个好主意,html中有两种选择框,即单选框和复选框,两者的区别是单选框中的选项用户只能选择一项,而复选框中用户可以任意选择多项,甚至全选. 语法: <input type="radio/checkbox" value="值" name="名称" checked="checked"/> 1.当type="radio"时,为单选框

气泡框箭头制作

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <style> 7 *{margin:0;padding:0;} 8 .arrow_box{ 9 position:relative; 10 background: #88b7d5; 11

【js与jquery】三级联动菜单的制作

1.效果如图所示: 2.html代码: [php] view plaincopy <li><span class="receiving">所在地区:</span> <span id="addr_select"> <select id='province_select' name='province'></select> <span id="city_select_poss&quo

是否存在未解决的bug

目前在网上,都是使用了听说,这两个字,形容agg,并且从07年开始就没有更新,作为不推荐使用的一种理由. 如下是个人的一些观点: 1)目前在使用的过程中没有发现任何的bug,当然了这里有一篇文章描述内存的,这是一种极端的情况,用户需要自己处理.希望其他人能够提供一个Bug报告,至少可以进行修改

iOS7上TableViewCell的button和UIImageView个别未显示的bug

要做这个cell,用xib将cell做成之后,在iPhone6.6Plus.5s上运行良好,但是在iOS7的5s和iPad上,黄色的小星星和下载按钮均没有显示. 甚为惊奇. 在网上百度之,发现了解决办法: -(void)layoutSubviews{ [super layoutSubviews]; self.contentView.frame = self.bounds; } 重写cell的这个方法即可. 个人认为是iOS7上的AutoLayout在显示时,对cell的frame计算方式和其他系

Android开发之一个未解决的bug

使用Activity之间传递数据的时候,出现了一个bug,但是没有找到哪里出错了. 把代码和log都记录下来,以后研究 代码: MainActivity.class 1 package com.example.caradviser; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import android.app.Activity; 7 import android.content.Intent; 8 import a

Leetcode 还未解决的bug

27. Remove Element val = 1 nums = [1,1,2,3] for i in nums: if i == val: nums.remove(i) a = nums result : val = 1 nums = [1,1,2,3] for i in nums[:]: if i == val: nums.remove(i) a = nums result: 不用remove的解法: class Solution(object): def removeElement(se

用js遍历生成数独可行数据(未优化 有bug版本)

var chess; var start; var end; //创建棋盘 function creatChess() { chess = new Array(); for (var i = 0; i < 9; i++) { chess[i] = new Array(); for (var j = 0; j < 9; j++) { chess[i][j] = 0; } } } //打印棋盘 function printChess() { var say = ""; for