Iphone 如何在已设置动画的UITableView上添加元素

Iphone 如何在已设置动画的UITableView上添加元素,iphone,uitableview,viewcontroller,Iphone,Uitableview,Viewcontroller,基本上,我试图通过编程方式在UITableView上添加一个视图。下面的代码将使UITableView的动画降低150像素,我想在上面创建的空间中添加元素。但每当我试图添加一些东西,比如代码中的标签,它就会消失。这是一个UITableViewController,所以我想这可能与它有关 救命啊 }将在 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if

基本上,我试图通过编程方式在UITableView上添加一个视图。下面的代码将使UITableView的动画降低150像素,我想在上面创建的空间中添加元素。但每当我试图添加一些东西,比如代码中的标签,它就会消失。这是一个UITableViewController,所以我想这可能与它有关

救命啊


}将在

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        return someViewIWantInMyHeader;
    }

}


不适合您?

如果要在视图顶部添加UILabel,可以将其添加到tableview的tableHeaderView属性中

分配UILabel并将其分配给tableHeaderView,即使您可以将此部分放入UIView动画中,它也会根据您的要求设置动画。

您可以使用

UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -30, 200, 30)];
testLabel.text = @"Hello";
testLabel.backgroundColor = [UIColor redColor];

tableView.tableHeaderView = testLabel;
[testLabel release];
//to add in footer tableView.tableFooterView = testLabel;
根据您的情况,您可以将其设置为零

tableView.tableHeaderView = testLabel;

读了这篇文章后,我有点让它工作了,但我尝试做的是模仿Engadget应用程序。在该应用程序的主屏幕上,如果单击右上角的箭头,它将向下滑动并显示所有engadget站点。就好像它被放在了应用程序代理或其他什么东西中一样。
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -30, 200, 30)];
testLabel.text = @"Hello";
testLabel.backgroundColor = [UIColor redColor];

tableView.tableHeaderView = testLabel;
[testLabel release];
//to add in footer tableView.tableFooterView = testLabel;
tableView.tableHeaderView = testLabel;