我在 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/