2012-04-19 36 views
0

在我的應用我有120行的UITableView中,每行有1個UItextfeilds和1個按鈕爲節目中的代碼波紋管:加強UITableView的滾動

-(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; 

}

我已經注意到,滾動速度慢,不流利。

有什麼想法嗎?

感謝

回答

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; 
1

那是因爲你創建的每一個時間文本框和按鈕,裏面if (cell == nil) {...}添加它。在if之外應該留下的唯一東西是textField文本設置。

順便說一句,你的文本字段泄漏。