IOS-TableView 方法

//

//  PersonViewController.m

//  UIImageViewDemo

//

//  Created by huguobin on 15/12/1.

//  Copyright (c) 2015 huguobin. All rights reserved.

//


#import "PersonViewController.h"

#import "PersonCell.h"

#import "SexCell.h"

#import "IconCell.h"

@interface PersonViewController ()


@end


@implementation PersonViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    states = [[NSMutableDictionary alloc]init];

    [states setObject:@"Lansing" forKey:@"Michigan"];

    [states setObject:@"Sacremento" forKey:@"California"];

    [states setObject:@"Albany" forKey:@"New York"];

    [states setObject:@"Phoenix" forKey:@"Arizona"];

    [states setObject:@"Tulsa" forKey:@"Oklahoma"];

    

    tableArray = [states allKeys];


    

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source


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

    

    return 1;

}


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

    // Return the number of rows in the section.

    return [tableArray count]+3;

}



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

    UITableViewCell *cell = nil;

    static NSString *customXibCellIdentifier = @"cell1";

   

    cell = [tableView dequeueReusableCellWithIdentifier:customXibCellIdentifier];

  //  tableView.separatorColor = [UIColor whiteColor];

//     tableView.separatorStyle = YES;

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (cell==nil)

    {

        if(indexPath.row==0){

             cell=[[[NSBundle mainBundle] loadNibNamed:@"PersonCell" owner:self options:nil]objectAtIndex:0];

          //   tableView.separatorStyle = NO;

            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

        }else if(indexPath.row==1){

             cell=[[[NSBundle mainBundle] loadNibNamed:@"SexCell" owner:self options:nil]objectAtIndex:0];

        //    tableView.separatorStyle = YES;


        }else if(indexPath.row==2){

            cell=[[[NSBundle mainBundle] loadNibNamed:@"IconCell" owner:self options:nil]objectAtIndex:0];

        }else{

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:customXibCellIdentifier];

            //Arrow

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        }

            

        

       

        

    }

    switch (indexPath.row) {

        case 0:

            [((PersonCell *)cell).name setText:@"胡国彬"];

            break;

        case 1:

            [((SexCell *)cell).sex setText:@""];

            break;

        case 2:

            break;

        case 3:

             cell.textLabel.text = [tableArray objectAtIndex:indexPath.row-1];

            

            

        default:

          

            

          

            break;

    }

   

    

    return cell;

}

//行高

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if(indexPath.row==2){

        return 100;

    }else

    

    return 40;

}


//点击每一行的颜色

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

//  // [tableView deselectRowAtIndexPath:indexPath animated:NO];

//    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

//    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; //(这种是没有点击后的阴影效果)


//    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

//    

//    cell.selected = NO; // (这种是点击的时候有效果,返回后效果消失)

//}

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

//    

//    cell.textLabel.backgroundColor = [UIColor redColor];

//}

//http://www.cnblogs.com/zcw-ios/articles/2574372.html

/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值