0

私のアプリでは、120行のUITableViewがあり、次のコードに示すように、すべての行に1つのUItextfeildsと1つのボタンがあります。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] 
             initWithStyle:UITableViewCellStyleDefault
             reuseIdentifier:CellIdentifier] autorelease];
}
else
{

}

UITextField *NameTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 10, 230, 28)];
NameTextField.borderStyle = UITextBorderStyleRoundedRect;

NameTextField.delegate = self;
NameTextField.textColor = UIColorFromRGB(0x2A1807);
NameTextField.font = [UIFont fontWithName:@"Helvetica" size:(17.0)];
NameTextField.font = [UIFont boldSystemFontOfSize:20];

NameTextField.tag = [indexPath row ];
NSString *temp = [self.sectionNames objectAtIndex:[indexPath section]];
NameTextField.text = [[self.myDataArray objectForKey:temp] objectAtIndex:[indexPath row]];
[cell.contentView addSubview:NameTextField];
[NameTextField release];
UIButton * aBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *wijzigImage = [UIImage imageNamed:@"btn_delete.png"];
aBtn.frame = CGRectMake(240, 10, 28, 26);
[aBtn setImage:wijzigImage forState:UIControlStateNormal];
[aBtn addTarget:self action:@selector(deleteCustomCellWithUIButton:) forControlEvents:UIControlEventTouchUpInside];


[cell.contentView addSubview:aBtn];
return cell;

}

スクロールが遅く、流暢に進まないことに気づきました。

何か案が ?

ありがとう

4

2 に答える 2

1

これは、毎回テキストフィールドとボタンを作成し、その中に追加するためif (cell == nil) {...}です。外に残しておくべき唯一のものifは、textFieldテキスト設定です。

ところで、あなたのテキストフィールドがリークします。

于 2012-04-19T18:41:21.950 に答える
1

私は解決策を見つけました:

if (cell == nil) {
    cell = [[[UITableViewCell alloc] 
             initWithStyle:UITableViewCellStyleDefault
             reuseIdentifier:CellIdentifier] autorelease];
}
else
{
UITextField *oldTextField = (UITextField *)[cell.contentView viewWithTag:999];
        [oldTextField removeFromSuperview];
        UIButton *oldBtn = (UIButton *)[cell.contentView viewWithTag:888];
        [oldBtn removeFromSuperview];
}
   NameTextField.tag = 999;

aBtn.tag = 88;
于 2012-04-19T18:58:11.717 に答える