保持顶级UiTableViewCell不滚动

时间:2014-08-13 21:35:30

标签: ios objective-c uitableview ios7

我有一个tableView,我使用第一个单元格作为表格的过滤器按钮。一旦点击,UiPickerView就会出现。

有没有办法让第一个单元格与表格的其余部分一起滚动并在导航栏下保持静态?

我的表格视图:

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

static NSString * teamCellIndentifier   = @"allEventsCell";
static NSString * filterCell            = @"filterCell";
UIColor *separator                      = [UIColor colorWithRed:220/255.0f green:220/255.0f blue:223/255.0f alpha:1];
UIColor *subtitle                       = [UIColor colorWithRed:100/255.0f green:100/255.0f blue:100/255.0f alpha:1];

if(indexPath.row != 0)
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:teamCellIndentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:teamCellIndentifier];
    }


    cell.textLabel.font                     = [UIFont fontWithName:@"HelveticaNeue" size:16.0];
    cell.textLabel.backgroundColor          = [UIColor clearColor];
    cell.textLabel.highlightedTextColor     = kPointstreakBlueColor;
    cell.textLabel.textColor                = subtitle;
    cell.accessoryType                      = UITableViewCellAccessoryDisclosureIndicator;
    cell.detailTextLabel.font                 = [UIFont fontWithName:@"HelveticaNeue" size:12.0];
    cell.detailTextLabel.backgroundColor      = [UIColor clearColor];
    cell.detailTextLabel.highlightedTextColor = kPointstreakBlueColor;
    cell.detailTextLabel.textColor            = subtitle;

    [self.tableView setSeparatorColor:separator];

    VideoClipData   * gameVideos    = [gameJsondataEventAry objectAtIndex:indexPath.row];
    VideoClip       * gameVideoData = [gameEventAry objectAtIndex:indexPath.row];

    // date formatting
    NSString        * str           = gameVideoData.evtCreatedSrt;
    NSDateFormatter * dateFormat    = [[NSDateFormatter alloc] init];
    NSLocale        * usLocale      = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

    [dateFormat setLocale:usLocale];
    [dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

    NSDate * dte = [dateFormat dateFromString:str];
    [dateFormat setDateFormat:@"MMM dd, YYYY - hh:mma"];

    cell.textLabel.text = gameVideos.evtTitleStr;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",[dateFormat stringFromDate:dte]];

    return cell;
}
else
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:filterCell];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:filterCell];
    }

    if(self.toggle == 0)
    {
        cell.textLabel.font                     = [UIFont fontWithName:@"HelveticaNeue" size:16.0];
        cell.backgroundColor                    = [UIColor whiteColor];
        cell.textLabel.highlightedTextColor     = kPointstreakBlueColor;
        cell.textLabel.textColor                = subtitle;
        cell.textLabel.textAlignment            = NSTextAlignmentCenter;
        cell.textLabel.text = @"Filter Events";
        return cell;
    }
    else
    {
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.textColor     = [UIColor redColor];
        cell.textLabel.text          = @"Cancel";
        return cell;
    }
}

}

感谢您的期待!

更新:

我能够像这样制作一个可点击的标题:

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 22)];
    UILabel* headerLabel = [[UILabel alloc] init];
    headerLabel.frame = CGRectMake(5, 2, tableView.frame.size.width - 5, 18);
    headerLabel.font = [UIFont boldSystemFontOfSize:16.0];
    headerLabel.text = @"Filter Evnets";
    headerLabel.userInteractionEnabled = YES;
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bringUpPickerViewWithRow:)];
    [headerLabel addGestureRecognizer:tapGesture];

    [headerView addSubview:headerLabel];

    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 70;
}

1 个答案:

答案 0 :(得分:3)

你应该把它作为你的节头,而不是第一个单元格。如果您有多个部分,您将希望它成为自己的视图(不是表视图的一部分)。