我有一個包含許多單元格的表格視圖。每個單元格都有自己的UITextField。我以編程方式添加了文本字段。我希望當編輯按鈕被擊中時,每個textField都會出現。 (現在表格處於編輯模式),再次按下時,我希望所有的textField消失(離開編輯模式)。我知道我可以使用hidden
屬性做到這一點,但我想在這種方法做這個:將UITextField添加到UITableViewCell只顯示最後一個單元格中的textField
- (IBAction)editButton:(id)sender
{
if (self.editing)
{
[self setEditing:NO animated:YES];
[self.myTableView setEditing:NO animated:YES];
EditButton.title = @"Edit";
cellText.hidden = YES; //<-- THIS IS THE CODE
}
else
{
[self setEditing:YES animated:YES];
[self.myTableView setEditing:YES animated:YES];
EditButton.title = @"Done";
cellText.hidden = NO; //<-- THIS IS THE CODE
}
}
,但只顯示和隱藏的最後小區的文本字段。我怎樣才能將它顯示在顯示位置,然後不顯示每個單元格的textFIeld?提前謝謝了!!!
提前ROW
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cellText = [[UITextField alloc]init];
[cellText setFrame:CGRectMake(190, 15, 55, 30)];
cellText.text = @"1";
cellText.borderStyle = UITextBorderStyleRoundedRect;
cellText.hidden = YES;
cellText.userInteractionEnabled = NO;
[cell addSubview:cellText];
}
return cell;
}
由於CELL! :D
你正在用的cellForRowAtIndexPath method.And一些代碼錯誤,請確保傳遞每個textField的標籤。請發佈該方法的一些代碼。它確實會幫助我們解決問題。 – 2012-01-12 04:31:13
好的!我會吧!感謝您的幫助! – iProRage 2012-01-12 04:32:06