我有一个grouped table with 3 categories and one header above the first one。我希望在用户输入他/她的名字后,标题标题用自己的名字更新自己。我在解雇第一个响应者(键盘)后,将reloadData
方法放在textFieldShouldReturn
中。它似乎并没有工作。标题标题保持不变。iOS更新标题标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
{
if(title==nil)
return @"Your name here...";
else
return title;
}
else return nil;
}
title
是NSString
它应该包含从标题单元格中的文本。
下面的代码是从cellForRowAtIndexPath
....
UITextField *txt = [[ UITextField alloc ] initWithFrame:CGRectMake(100,10, 200, 30)];``
txt.delegate = self;
[cell addSubview:txt];
if(indexPath.section==0)
{
if([indexPath row] == 0)
{
[cell.textLabel setText:@"Name"];
title = txt.text;
}
谢谢!
您可以修改您的原始问题以显示“UITextField * txt = ...'初始化程序被调用的位置/方式吗?现在我怀疑你总是不停地调用alloc/init方法,因此你的'title'变量总是被设置为NULL。 – 2012-01-05 11:32:27
'reloadData'只重新载入表格单元格或整个表格,包括页眉和页脚? – Teo 2012-01-05 11:37:23