tableview delegate 详解

来源:互联网 发布:冰岛 知乎 编辑:程序博客网 时间:2024/05/17 03:42

#pragma TableViewDelegate

分组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return self.dataSource.count;

}

每组的行数

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

{

   return [[self.dataSourceobjectAtIndex:section]count];

    

}

cell高度

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

{

   if (indexPath.section ==0) {

           return 70;

    }

   else

    {

       return 44;

    }

}

cell头的高度

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

{

   if (section == 0)

    {

       return 0;

    }

   else

    {

   return 25;

    }

}

cell脚的高度

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

{

   if (section == 3 ) {

       return 70;

    }

   else

    {

       return 0;

    }

    

}

脚的自定义

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

{

   if (section == 3) {

       UIView * footView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, tableView.frame.size.width,70)];

        

       UIButton *button1=[[UIButtonalloc]initWithFrame:CGRectMake(35,20, tableView.frame.size.width-35*2,40)];

        

        [button1 setBackgroundImage:[UIImageimageNamed:@"01确定按钮.png"]forState:UIControlStateNormal ];

        [button1 setTitle:@"退出登录"forState:UIControlStateNormal ];

        [button1 addTarget:selfaction:@selector(quite:)forControlEvents:UIControlEventTouchUpInside ];

        [footView setBackgroundColor:[UIColorclearColor]];

        [footViewaddSubview:button1];

       return footView ;

    }

   else

    {

       return 0;

    }

    

}


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

{

   static NSString * identifier =@"identifier3";

   setTableViewCell * cell = (setTableViewCell*)[[tableViewdequeueReusableCellWithIdentifier:identifier]lastObject];

   if (cell == nil)

    {

        cell = [[[NSBundlemainBundle]loadNibNamed:@"setTableViewCell"owner:selfoptions:nil]lastObject];

        [cell setSelectionStyle:UITableViewCellSelectionStyleGray];

    }

   if (indexPath.section ==0)

    {

        cell.TX_image.frame =CGRectMake(20,20, 40, 40);

        cell.MX_label.frame =CGRectMake(70,30, 200, 30);

        cell.TP_image.frame =CGRectMake(SCREEN_WIDTH-30,80/2-14/2 ,7,14);

    }

   else

    {

        cell.TX_image.frame =CGRectMake(20,20, 20, 20);

        cell.MX_label.frame =CGRectMake(50,10, 200, 30);

        cell.TP_image.frame =CGRectMake(SCREEN_WIDTH-30,44/2-14/2,7, 14);


    }

   NSString * TX = [[[self.dataSourceobjectAtIndex:indexPath.section]objectAtIndex:indexPath.row]objectForKey:@"TX"];

    cell.TX_image.image = [UIImageimageNamed:TX];

    cell.MX_label.text = [[[self.dataSourceobjectAtIndex:indexPath.section]objectAtIndex:indexPath.row]objectForKey:@"MC"];

    cell.TP_image.image = [UIImageimageNamed:@"setting_arrow.png"];

   

    

   return cell;


}

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

{

   if (indexPath.section ==0)

    {

       NSLog(@"啊哈0");

 

        privateMessageViewController * pM = [[privateMessageViewControlleralloc]init];


        [self.navigationControllerpushViewController:pM animated:YES];

        

    }

   else if (indexPath.section ==1)

    {

       if (indexPath.row ==0)

        {

           NSString * str = @"child";

            [selfchildOrClass:str];

       

        }

       else

        {

           NSString * str = @"class";

            [selfchildOrClass:str];

        }

    }

   else if (indexPath.section ==2)

    {

       NSLog(@"啊哈2");

        NotFriendlyViewController * notFriendly = [[NotFriendlyViewControlleralloc]init];

        [self.navigationControllerpushViewController:notFriendly animated:YES];

    }

   else if (indexPath.section ==3)

    {

       if (indexPath.row ==0) {

            privateSetViewController * privaSet = [[privateSetViewControlleralloc]init];

            [self.navigationControllerpushViewController:privaSet animated:YES];

                    }

       else if (indexPath.row ==1)

        {

            FeedBackViewController * feedBack = [[FeedBackViewControlleralloc]init];

            [self.navigationControllerpushViewController:feedBack animated:YES];


        }

    }

}

0 0
原创粉丝点击