iphone - 使用自定义节标题将行添加到 tableView

标签 iphone objective-c ios cocoa-touch uitableview

我有一个问题,当我向表中添加行(带动画)时,节标题不会移动。我在 viewDidLoad 中创建节标题,如下所示:

CGRect header = [self.tableView rectForHeaderInSection:0];
UILabel *label = [[UILabel alloc] initWithFrame:headerFrame];
[label setText:@"---"];
label.backgroundColor = [UIColor clearColor];
[label setFont:headerFont];
[label setTextColor:[UIColor blueColor]];
[self.tableView addSubview:label];
[label release];

我应该以不同的方式添加它们吗? (是的,我意识到这些是自定义表格标题,这就是我想要的)

我有一个用户使用选择器添加行。行的添加方式如下:

    NSIndexPath* path = [NSIndexPath indexPathForRow:chan.channel_number inSection:section_number];

    NSArray* row_to_add = [[NSArray alloc] initWithObjects:path , nil];
    [self.tableView insertRowsAtIndexPaths:row_to_add withRowAnimation:UITableViewRowAnimationRight];

行添加得很好,但我的标题 View 没有改变。如何让我的标题重新定位?

最佳答案

您需要使用真实的标题。您可以使用委托(delegate)方法 tableView:viewForHeaderinSection: 并返回 UILabel。

关于iphone - 使用自定义节标题将行添加到 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7017536/

相关文章:

ios - Xcode 生成 NSManagedObject 子类问题

javascript - 自动化测试 performTaskWithPathArgumentsTimeout 在命令行中不起作用?

c++ - 结构的构造函数

iphone - 如何在 UITableViewCell 的子类中管理旋转

ios - 无法使用 setPitchEnabled 将其值更改为 YES

ios - 无法将推送通知从 AWS SNS 发送到我的 iPad

ios - UITextField 选中时清除,但如果没有输入也恢复数据

ios - 如何在 Xcode 6 上设置 svn 存储库?

ios - NSInvalidArgumentException',原因 : 'Application tried to present a nil modal view controller on target

iphone - admob/adsense 如何在 android 应用程序中工作?