Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone的tableview中的最后一行添加文本字段?_Iphone_Tableview - Fatal编程技术网

如何在iPhone的tableview中的最后一行添加文本字段?

如何在iPhone的tableview中的最后一行添加文本字段?,iphone,tableview,Iphone,Tableview,当我按下new按钮时,我需要在tableview的最后一行添加一个textfield 谁能解释一下这个流程 提前谢谢。我对iphone编码非常陌生,我想与大家分享我的想法。如果这是错误的,请忽略 在cellforrowatinexpath方法中,您需要在中设置textfield if(indexPath.row==numberOfRows-1)条件。 在按钮按压方法中,U可以设置文本字段。隐藏=NO/,并且在 VIELDDATABORE TeXField.隐藏=“是”/代码> < P>如果

当我按下new按钮时,我需要在tableview的最后一行添加一个textfield

谁能解释一下这个流程


提前谢谢。

我对iphone编码非常陌生,我想与大家分享我的想法。如果这是错误的,请忽略

cellforrowatinexpath
方法中,您需要在中设置
textfield
if(indexPath.row==numberOfRows-1)
条件。
在按钮按压方法中,U可以设置<代码>文本字段。隐藏=NO/<代码>,并且在<代码> VIELDDATABORE <代码> TeXField.隐藏=“是”/代码>

< P>如果您只希望文本字段出现在表的末尾,为什么不考虑使用UITababVIEW的TabLoFutTeVIEW属性?

在这种情况下,您不必确保在委托方法中返回UITextField


如果您使用的是InterfaceBuilder或XCode 4,那么您几乎可以在Tableview中拖放一个新的UITextField。

我刚刚尝试过这个场景

像这样创建一个单布尔变量 BOOL newButtonPress=否

然后休耕下面的代码

-(IBAction)newButtonClicked:(id)sender{
if (self.newButtonPress == NO) {
//if new button press then newbuttpress is yes and reload the tableview
self.newButtonPress = YES;
[self .reloadTableview reloadData];
    }   
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(self.newButtonPress == YES)//creating noOfRows when newbutton pressed
{
    return [self.itemNames count]+1;
}
else {
    return [self.itemNames count]; 
   }
}
然后将下面的代码添加到CellForRowatineXpath方法中

//when new button is pressed adding new cell
if (self.newButtonPress == YES) {
    if([self.itemNames count] == [indexPath row]){
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //creating the textfield if new button is pressed 
        UITextField *extraField = [[UITextField alloc] initWithFrame:CGRectMake(80, 6, 100, 30)];
        extraField.borderStyle = UITextBorderStyleNone;
        extraField.textAlignment = UITextAlignmentCenter;
        [extraField becomeFirstResponder];
        [extraField setDelegate:self];
        [cell addSubview:extraField];
        [extraField release];
    }
}