我有四個部分第一截面的tableview具有這樣前六行7列具有文本字段和最後一行具有兩個文本框泰伯維[cell.contentview viewwithtag:]被返回nil
第一節
T1
T1
T1
T1
T1
T1
T1 T2
部2
T1 T2
T1 T2 //第二行文本框被放置在第四行
T1 T2
T1 T2 //第四行文本框被放置在某些其它行
T1 T2
T1 T2
T1 T2
部3
T1 T2
T1 T2
T1 T2
T1 T2
T1 T2
T1 T2
T1 T2
部4
T1
T1
T1
T1
T1
t1
T1
T1
二&第三部分包含有兩個文本框的每個
第四節已經包含各行中的一個文本框八行我安排一個獨特的標籤,所有的文本框七行
在textFieldDidEndEditing我將內容保存到適當的索引中的數組。
如果我在滾動文本字段中輸入數據後的tableview。一些文本字段位置被改變(即)第二行中的文本字段被放置在第三行中,類似地一些行被交換。
我已創建5個小區標識符一個用於在段中的一個前六行,第二個用於在所述第一部分中的最後一行,併爲剩餘的其他部分3的小區標識符。
當我滾動有時cell.contentview viewWithtag返回標籤
零價值,我認爲這是在某些行文本框錯誤的原因。
如何糾正這個問題?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier;<bn>
UITableViewCellStyle style = UITableViewCellStyleDefault;<br>
BOOL selectable = NO;<br>
switch (indexPath.section)
{
case 0:
{
if(indexPath.row < 6)
identifier = @"firstsectionSixRows";
else
identifier = @"firstsectionLastRow";
break;
}
case 1:
identifier = @"secondsection";
break;
case 2:
identifier = @"thirdsection";
break;
case 3:
identifier = @"fourthsection";
break;
}
return [self createCellForIdentifier:identifier
tableView:tableView
indexPath:indexPath
style:style
selectable:selectable];
}
在createCellForIdentifier方法
else if([identifier isEqualToString:@"secondsection"])
{
int TextTag = 8 + indexPath.row * 2;
UILabel *lblName = (UILabel*)[cell.contentView viewWithTag:10000];
lblName.text = [NSString stringWithFormat:@"G%d",indexPath.row + 1];
//NSLog(@"row = %d texttag = %d",indexPath.row,TextTag);
UITextField *txtFirst = (UITextField*) [cell.contentView viewWithTag:TextTag];
if([textFieldArray count] > 0)
{
if(![[textFieldArray objectAtIndex:TextTag] isEqualToString:@""])
{
if(txtFirst)
txtFirst.text = [NSString stringWithFormat:@"%@",[textFieldArray objectAtIndex:TextTag]];
else
NSLog(@"Textfield is nil \n tag = %d \n cell section = %d row = %d",TextTag,indexPath.section,indexPath.row);
}
}
UITextField *txtSecond = (UITextField*) [cell.contentView viewWithTag:TextTag + 1];
if([textFieldArray count] > 0)
{
if(![[textFieldArray objectAtIndex:TextTag + 1] isEqualToString:@""])
{
if(txtSecond)
txtSecond.text = [NSString stringWithFormat:@"%@",[textFieldArray objectAtIndex:TextTag + 1]];
else
NSLog(@"Textfield is nil \n tag = %d \n cell section = %d row = %d",TextTag + 1,indexPath.section,indexPath.row);
}
}
}
發佈您的代碼。 – 2010-10-29 15:51:54