ios - 如何使每一行都有自己的标题,并具有类似节的行为?

标签 ios header row each

我在 xcode 中遇到了一个小问题:

我想为我的数组中的每一行创建一个带有单独标题的 TableView - 就像在 Instagram 应用程序中完成的一样,但我无法弄清楚如何从部分中获取行为(一个接一个地推)离开屏幕,但当您处于“标题之间”时,仍锚定在导航栏的底部)。

我可以制作多个部分,或者我可以使用 1 个部分制作多个行,但我无法弄清楚如何制作 X 个部分,每个部分有 1 行,并且仍然跟踪行(indexPath搞砸了,显而易见)。

我想向您展示很多代码,但我还没有真正接近解决我的问题...

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
return [array count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [array count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
return 1;
}

最佳答案

好的,如果有人对制作带有标题的表格 View (很像 Instagram 表格 View )感兴趣,那么这里就是答案:

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [yourArray count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return 1;

}


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

    static NSString *CellIdentifier = @"Cell";

    CustomCell *cell = [TableName dequeueReusableCellWithIdentifier:CellIdentifier];
    if(!cell) {
        cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }


cell.bodyText.text = [[yourArray objectAtIndex:indexPath.section] objectForKey:@"bodytext"];

return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[yourArray objectAtIndex:section] objectForKey:@"headertext"];

}

关于ios - 如何使每一行都有自己的标题,并具有类似节的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19695268/

相关文章:

ios - UIViewController 没有立即出现

c# - Xamarin Forms (IOS) 中的图像 slider CarouselView 问题

ios - 如何在tableview中同时插入多行?

html - 具有两个不同标题的网站

php - 从数据库中检索特定行并显示特定行中的所有数据并使用 php 发送 json

r - 如何逐行求和?

sql按ID组合行,保留信息

objective-c - 为什么类型为 id<someProtocol> 的变量不能接收 id<otherProtocol> 的参数,即使 'otherProtocol' 符合 'someProtocol' ?

java - 如何增加 Tomcat Java header 大小限制

mysql - 如何在创建时复制行?