一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

TableView的詳細(xì)設(shè)置

 昵稱20917807 2014-12-11
// 頭文件

//

//  GroupTableViewController.h

//  UITableViewGroup

//

//  Created by LiZe on 13-9-5.

//  Copyright (c) 2013 BlackCode. All rights reserved.

//

#import

#import "DetailViewController.h"

@interface GroupTableViewController : UIViewController<</span>UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) UITableView *groupTableView;

@end





 //

//  GroupTableViewController.m

//  UITableViewGroup

//

//  Created by LiZe on 13-9-5.

//  Copyright (c) 2013 BlackCode. All rights reserved.

//

#import "GroupTableViewController.h"

@interface GroupTableViewController ()


@end


@implementation GroupTableViewController


- (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.

    // 設(shè)置標(biāo)題

    self.title = @"UITableView Group 的使用";

    

    // 初始化groupTableView

    self.groupTableView = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped] autorelease];

    // 設(shè)置表示圖的數(shù)據(jù)源委托

    _groupTableView.dataSource = self;

    // 設(shè)置表示圖的委托

    _groupTableView.delegate = self;

    // 設(shè)置groupTableView的背景顏色

    UIView *groupTableViewBGView = [[UIView alloc] initWithFrame:self.view.frame];

    groupTableViewBGView.backgroundColor = [UIColor brownColor];

    _groupTableView.backgroundView = groupTableViewBGView;

    [groupTableViewBGView release], groupTableViewBGView = nil;

    

    // 添加到當(dāng)前視圖中

    [self.view addSubview:_groupTableView];

    

    

    // 在導(dǎo)航欄上添加一個(gè)編輯按鈕放在右上角

    UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"編輯" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleButton:)];

    

    self.navigationItem.rightBarButtonItem = editButton;

    [editButton release], editButton = nil;

    

    // 在導(dǎo)航欄上添加一個(gè)提示按鈕放在左上角

    UIBarButtonItem *hintLeftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil];

    self.navigationItem.leftBarButtonItem = hintLeftButton;

    [hintLeftButton release], hintLeftButton = nil;

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



#pragma mark - 實(shí)現(xiàn)---編輯按鈕的toggleButton:方法

- (void)toggleButton:(UIBarButtonItem *) sender {

    if (_groupTableView.isEditing == YES) {

        [_groupTableView setEditing:NO animated:YES];

        sender.title = @"編輯";

    } else {

        [_groupTableView setEditing:YES animated:YES];

        sender.title = @"完成";

    }

}


#pragma mark - 重寫----設(shè)置有groupTableView有幾個(gè)分區(qū)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 4; // 返回值是多少既有幾個(gè)分區(qū)

}


#pragma mark - 重寫----設(shè)置每個(gè)分區(qū)有幾個(gè)單元格

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    // 分別設(shè)置每個(gè)分組上面顯示的單元格個(gè)數(shù)

    switch (section) {

        case 0:

            return 3;

            break;

        case 1:

            return 2;

            break;

        case 2:

            return 5;

            break;

        case 3:

            return 10;

            break;

        default:

            break;

    }

    return 10;

}


#pragma mark - 重寫----設(shè)置每個(gè)分組單元格中顯示的內(nèi)容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // 設(shè)置一個(gè)標(biāo)示符

    static NSString *cell_id = @"cell_id";

    //

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id];

    // 判斷cell是否存在

    if (!cell) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id] autorelease];

        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    }

    // 分別給每個(gè)分區(qū)的單元格設(shè)置顯示的內(nèi)容

   

    cell.textLabel.text = [NSString stringWithFormat:@"section = %d, row = %d", indexPath.section, indexPath.row];

    return cell;

}


#pragma mark - 重寫----設(shè)置哪個(gè)單元格被選中的方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"單元格" message:[NSString stringWithFormat:@"section = %d, row = %d", indexPath.section, indexPath.row] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確認(rèn)", nil];

    [alertView show];

    [alertView release], alertView = nil;

}


#pragma mark - 重寫----設(shè)置每個(gè)單元格上面的按鈕的點(diǎn)擊方法

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {

    // 實(shí)例化DetailViewController

    DetailViewController *detailVC = [[DetailViewController alloc] init];

    // 添加出一個(gè)導(dǎo)航欄

    UINavigationController *navigtion = [[UINavigationController alloc] initWithRootViewController:detailVC];

    // 設(shè)置導(dǎo)航欄顏色

    navigtion.navigationBar.tintColor = [UIColor purpleColor];

    // 設(shè)置模態(tài)視圖彈出的動(dòng)畫效果

    navigtion.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    // 直接使用self呈現(xiàn)一個(gè)試圖

    [self presentViewController:navigtion animated:YES completion:nil];

    // 釋放內(nèi)存

    [detailVC release], detailVC = nil;

}


#pragma mark - 重寫----設(shè)置標(biāo)題和標(biāo)注的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 30.0f;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

    return 20.0f;

}


#pragma mark - 重寫----設(shè)置標(biāo)題和標(biāo)注

 



#pragma mark - 重寫----設(shè)置自定義的標(biāo)題和標(biāo)注

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];;

    headerLabel.font = [UIFont boldSystemFontOfSize:18.0f];

    headerLabel.backgroundColor = [UIColor clearColor];

    headerLabel.text = @"  我是標(biāo)題";

    headerLabel.textColor = [UIColor blackColor];

    return headerLabel;

    

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    UILabel *footerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];;

    footerLabel.font = [UIFont boldSystemFontOfSize:15.0f];

    footerLabel.backgroundColor = [UIColor clearColor];

    footerLabel.textAlignment = NSTextAlignmentCenter;

    footerLabel.text = @"(*^__^*) 嘻嘻……";

    footerLabel.textColor = [UIColor whiteColor];

    return footerLabel;

}



#pragma mark - 重寫----設(shè)置單元格可以排序

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {

    return YES;

}


#pragma mark - 重寫----設(shè)置排序執(zhí)行的方法

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {

    

}


#pragma mark - 重寫----設(shè)置單元格隔行換顏色

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row % 2 == 0) {

        cell.backgroundColor = [UIColor orangeColor];

    } else {

        cell.backgroundColor = [UIColor yellowColor];

    }

}


#pragma mark - 重寫----設(shè)置groupTableView可以編輯

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

    return YES;

}


#pragma mark - 重寫----設(shè)置編輯狀態(tài)下左面顯示的是加號(hào)、減號(hào)、還是空白

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}


#pragma mark - 重寫----根據(jù)編輯的狀態(tài)來(lái)執(zhí)行什么操作

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    // 根據(jù)編輯狀態(tài)進(jìn)行相應(yīng)的操作

    if (editingStyle == UITableViewCellEditingStyleInsert) { // 進(jìn)行插入的操作

        

        

    } else if (editingStyle == UITableViewCellEditingStyleDelete) { // 進(jìn)行刪除的操作

       

    }

}




#pragma mark - 重寫----dealloc方法

- (void)dealloc {

    [_groupTableView release], _groupTableView = nil;

    

    

    [super dealloc];

}


@end

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多

    成人精品国产亚洲av久久| 午夜精品久久久99热连载| 日本不卡视频在线观看| 国产欧美日韩在线一区二区| 午夜精品麻豆视频91| 国产一区二区在线免费| 搡老熟女老女人一区二区| 国产又粗又猛又大爽又黄| 亚洲午夜福利视频在线| 日本人妻精品有码字幕| 91久久国产福利自产拍| 欧美熟妇一区二区在线| 日韩女优精品一区二区三区| 日韩中文字幕狠狠人妻| 国产成人免费高潮激情电| 国产传媒精品视频一区| 伊人国产精选免费观看在线视频 | 国产91麻豆精品成人区| 午夜精品一区二区av| 久久黄片免费播放大全| 香蕉尹人视频在线精品| 殴美女美女大码性淫生活在线播放| 日韩欧美国产亚洲一区| 人妻偷人精品一区二区三区不卡| 国产日韩久久精品一区| 国产91麻豆精品成人区| 老司机精品视频在线免费看| 经典欧美熟女激情综合网| 国产女优视频一区二区| 免费特黄欧美亚洲黄片| 欧美一级特黄大片做受大屁股| 一区二区欧美另类稀缺| 精品人妻一区二区三区在线看| 亚洲欧洲一区二区中文字幕| 亚洲av专区在线观看| 中文字幕在线五月婷婷| 欧美黑人黄色一区二区| 国产亚洲欧美一区二区| 午夜精品国产一区在线观看| 成人国产激情在线视频| 97人妻人人揉人人躁人人|