IOS - UITableview中的UISegmented

时间:2012-12-06 16:11:08

标签: ios uitableview

我在uitableview like this url image中插入了一个分段。如果您看到网址图片,现在我正在使用uitable中的所有数据,

和...

当我向下滚动表格时,我想要第1部分:图像(在网址中)将滚动滚动到第2部分:分段将停止,如果您仍然滚动到第3部分:数据将滚动(保持在顶部分段)。

你知道吗?感谢

1 个答案:

答案 0 :(得分:2)

我只是测试它,它正在工作!

  1. 设置您的UITableView痛苦

  2. UITableView有两个部分,每个部分只有一行。

  3. 编辑章节标题时,请确保只有第二个标题有标题 - 第二个标题将是您的第2部分。

  4. 第一部分的第一行是你的第1部分。

  5. 第二部分的第一行是你的第3部分。

  6. 就是这样:))

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return 2;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 1;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
            static NSString *CellIdentifier = @"Cell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
    
            cell.textLabel.text = @"test";
    
            return cell;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
        @try {
            UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
            switch (section) {
                case 0:
                {
                    //nothing
                }
                    break;
                case 1:
                {
                    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
                    lbl.text = @"second";
                    lbl.textColor = [UIColor blackColor];
                    [containerView addSubview:lbl];
                }
                    break;
            }
            return containerView;
        }
        @catch (NSException *exception) {
        }
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
        return 30;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 1000.0;
    }