代码之家  ›  专栏  ›  技术社区  ›  Kevin Bomberry

如何在TableView:ViewForFooterInSection中添加uiButton或uiSwitch

  •  6
  • Kevin Bomberry  · 技术社区  · 16 年前

    我试图理解如何将带有uiswitch或其他控制器的标签添加到分区表视图的页脚(或页眉)中。任何帮助都将不胜感激。提前谢谢!

    2 回复  |  直到 12 年前
        1
  •  8
  •   Dan D.    12 年前

    好吧,在搜索和研究之后,我做了以下工作:

    // Need to refactor so that the label is Public Sharing and Priviate Sharing and the actions work for each switch
    - (UIView *) tableView: (UITableView *) tableView
    viewForFooterInSection: (NSInteger) section
    {
      if (section == 0 || section == 1) {
        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
        UIView* footerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)] autorelease];
        footerView.autoresizesSubviews = YES;
        footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        footerView.userInteractionEnabled = YES;
    
        footerView.hidden = NO;
        footerView.multipleTouchEnabled = NO;
        footerView.opaque = NO;
        footerView.contentMode = UIViewContentModeScaleToFill;
    
        // Add the label
        UILabel*    footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(150.0, -5.0, 120.0, 45.0)];
        footerLabel.backgroundColor = [UIColor clearColor];
        footerLabel.opaque = NO;
        footerLabel.text = @"Sharing";
        footerLabel.textColor = [UIColor tableHeaderAndFooterColor];
        footerLabel.highlightedTextColor = [UIColor tableHeaderAndFooterColor];
        footerLabel.font = [UIFont boldSystemFontOfSize:17];
        footerLabel.shadowColor = [UIColor whiteColor];
        footerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
        [footerView addSubview: footerLabel];
    
        [footerLabel release];  
    
        // Add the switch
        UISwitch* footerSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(215.0, 5, 80.0, 45.0)];
        [footerView addSubview: footerSwitch];
    
        // Return the footerView
        return footerView;
      }
      else return nil;
    }
    // Need to call to pad the footer height otherwise the footer collapses
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
      switch (section) {
        case 0:
        case 1:
          return 40.0;
        default:
          return 0.0;
      }
    }
    

    我希望这是正确的,如果这有助于任何其他人请投票表决。干杯!

        2
  •  0
  •   dave    15 年前

    我想你需要重新发布uiview-

    推荐文章