gpt4 book ai didi

ios:uitableview 部分标题 anchor 到表顶部

转载 作者:IT王子 更新时间:2023-10-29 07:59:02 26 4
gpt4 key购买 nike

我正在尝试制作一个包含多个部分的表格(比如联系人应用程序) 一切顺利,我在每个部分的顶部创建了自定义部分标题,显示代表该部分的字符..问题是我希望它就像 Contact 一样,标题停留在顶部,直到下一个标题与它一起崩溃。 ..这怎么会发生

我正在使用下面的代码(让你更容易理解

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return [stateIndex count];
}



- (UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section
{

UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
sectionHeader.backgroundColor = [UIColor clearColor];
sectionHeader.font = [UIFont boldSystemFontOfSize:18];
sectionHeader.textColor = [UIColor whiteColor];
sectionHeader.text = [stateIndex objectAtIndex:section];
sectionHeader.textAlignment=UITextAlignmentCenter;
return sectionHeader;
}
//---set the index for the table---
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return stateIndex;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

//---get the letter in each section; e.g., A, B, C, etc.---
NSString *alphabet = [stateIndex objectAtIndex:section];

//---get all states beginning with the letter---
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSArray *states = [resultPoets filteredArrayUsingPredicate:predicate];

//---return the number of states beginning with the letter---
return [states count];

}


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

static NSString *CellIdentifier = @"Cell";
PoemsCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
int row = indexPath.row;




//---get the letter in the current section---
NSString *alphabet = [stateIndex objectAtIndex:[indexPath section]];

//---get all states beginning with the letter---
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSArray *states = [resultPoets filteredArrayUsingPredicate:predicate];

if ([states count]>0) {
//---extract the relevant state from the states object---
NSString *cellValue = [states objectAtIndex:row];

cell.poemText.text = cellValue;

}



return cell;
}

最佳答案

如果您使用 TableView 样式“普通”而不是“分组”,这应该会自动工作。

来自文档:

UITableViewStylePlain: A plain table view. Any section headers or footers are displayed as inline separators and float when the table view is scrolled.

UITableViewStyleGrouped: A table view whose sections present distinct groups of rows. The section headers and footers do not float.

关于ios:uitableview 部分标题 anchor 到表顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13249261/

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