2011-11-11 44 views
1

我已经定制了UITableViewCell,我有一个UILabelUIButton。我已经在layoutSubviews方法中设置了框架,该表格已经自定义了UITableViewCell,我在三个地方使用了该方法,但我需要删除第二位的UIButton。怎么做 ?如何从UITableViewCell中删除按钮?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    CustomPopTableViewCell *cell = (CustomPopTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[CustomPopTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    cell.accessoryType = UITableViewCellAccessoryNone; 
    if(tableView.tag == e_metadataView) 
    { 
     //cell.mCheakMarkButton.frame=CGRectZero; 
     cell.mTaggedTerm.text = [docInfoCollection objectAtIndex:indexPath.row]; 
    } 
    else if(tableView.tag == e_searchSettingView)   
    { 
     if(indexPath.row == self.currentRow) 
     { 
      [cell.mcheckMarkButton removeFromSuperView]; 
     } 
     cell.mTaggedTerm.text = [searchEngineCollection objectAtIndex:indexPath.row]; 
    } 
    else if(tableView.tag == e_TaggedTermView)//tageed term table 
    { 
     TaggedItems *taggedItem = [documentData.taggedWords objectAtIndex : indexPath.row]; 
     cell.mTaggedTerm.text = taggedItem.keyword; 
     if([self isTappedObjectExist:indexPath.row]) 
     { 
      cell.accessoryType = UITableViewCellAccessoryCheckmark; 
     } 


    } 

    return cell; 
} 

回答

3

我会用:

for (UIView* v in cell.subviews) { 
    if ([v isKindOfClass:[UIButton class]]) { 
     [v removeFromSuperView]; 
    } 
} 

如果你有,当然你的自定义单元格的观点的中介水平进行修正。如果你有几个按钮,我会用标签来标识它。

+0

它是removeFromSuperview,“v”很小:) –