zoukankan      html  css  js  c++  java
  • UI4_UITableViewEdit

    //
    //  AppDelegate.m
    //  UI4_UITableViewEdit
    //
    //  Created by zhangxueming on 15/7/13.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "AppDelegate.h"
    #import "ViewController.h"
    
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        ViewController *root = [[ViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
        self.window.rootViewController = nav;
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        
        return YES;
    }
    
    
    //
    //  ViewController.h
    //  UI4_UITableViewEdit
    //
    //  Created by zhangxueming on 15/7/13.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
    
    
    @end
    
    //
    //  ViewController.m
    //  UI4_UITableViewEdit
    //
    //  Created by zhangxueming on 15/7/13.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    {
        UITableView *_tableView;
        NSMutableArray *_dataList;
    }
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
        [self.view addSubview:_tableView];
        
        //创建数据源
        _dataList = [NSMutableArray array];
        
        NSMutableArray *boys = [NSMutableArray array];
        for (int i=0; i<10; i++) {
            NSString *name = [NSString stringWithFormat:@"boy%d", i];
            [boys addObject:name];
        }
        [_dataList addObject:boys];
        
        NSMutableArray *grils = [NSMutableArray array];
        for (int i=0; i<15; i++) {
            NSString *name = [NSString stringWithFormat:@"gril%d", i];
            [grils addObject:name];
        }
        [_dataList addObject:grils];
        
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        //编辑状态
        self.navigationItem.leftBarButtonItem = self.editButtonItem;
    }
    
    //设置表示图到编辑状态
    
    - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing:editing animated:animated];
        //让tableView处在编辑状态
        [_tableView setEditing:editing animated:YES];
    }
    
    #pragma mark ---UITableViewDataSource---
    //返回分区的行数
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [[_dataList objectAtIndex:section] count];
    }
    
    //返回分区的个数
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return _dataList.count;
    }
    
    //创建UITableViewCell
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *reuseIdentifier = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
        }
        NSArray *array = [_dataList objectAtIndex:indexPath.section];
        cell.textLabel.text = [array objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"age:%d",arc4random()%40+10];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        return cell;
    }
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        if (section==0) {
            return @"男孩";
        }
        return @"女孩";
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    
  • 相关阅读:
    C-Scanf连续调用多次并且存在%c的问题
    JavaScript-常用正则函数(适合忘记时看)
    JavaScript-深入理解JavaScript(一、预编译和执行过程)
    Python-代码性能优化技巧
    Python-深入理解元类(metaclass)
    Python-编码之大彻大悟
    Python-正确使用Unicode
    Fiddler-抓取安卓手机APP请求地址
    unity, access sprite of UGUI Image
    unity, UGUI Text outline
  • 原文地址:https://www.cnblogs.com/0515offer/p/4643558.html
Copyright © 2011-2022 走看看