gpt4 book ai didi

IOS - UITableview 中的 UISegmented

转载 作者:行者123 更新时间:2023-11-28 22:43:56 25 4
gpt4 key购买 nike

我在 uitableview 中插入一个分段 like this url image .如果您看到 url 图片,那么我现在工作正常,所有数据都在 uitable 中,

和...

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

你知道吗?谢谢

最佳答案

我刚刚测试了一下,它工作正常!

  1. 设置你的 UITableView 痛苦

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

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

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

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

就是这样:)

- (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;
}

关于IOS - UITableview 中的 UISegmented,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13747748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com