首页 > 代码库 > 得到cell视图

得到cell视图

我 使用了dequeueReusableCellWithIdentifier方法为tableview加载cell,然后为cell添加了两个子视图。为 了使dequeueReusableCellWithIdentifier加载的每个cell都是空的,我在 dequeueReusableCellWithIdentifier方法后面添加了移除cell的子视图的方法。现在问题出现了,其中一个子视图恢复正 常,另一个视图却消失了。麻烦大家看一下这是什么问题?相关代码附在下面:

想实现的效果应该是点击cell出现tmpView_section这个视图,而在cell上左右滑动出现tmpView视图,而现在tmpView_section这个视图消失了

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当用户点击cell的时候调用该方法
    NSLog(@\"点击cell\");
    ifselectedCell = YES;           //设置为YEs表示这个cell被点击
    [tmpView_setIcon setHidden:NO]; //将设置Icon的UIImageView显示出来
    ABPerson *person = [self.PersonArray objectAtIndex:indexPath.row];//得到这一行的人的信息
    selectedRow = indexPath.row;    //
    NSString *name = person.Person_Name;
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];//得到这一行被点击的Cell
    cell.textLabel.text = [NSString stringWithFormat:@\"\\t\\t\\t\\t\\t\\t%@\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\",name];
    cell.textLabel.font = [UIFont systemFontOfSize:22];
    cell.textLabel.textAlignment = UITextAlignmentLeft;
    cell.textLabel.textColor = [UIColor colorWithRed:0.939 green:0.932 blue:0.930 alpha:1.000];

    [self.tableView reloadData];

   //smallicon-01按钮        
    CustomButton *button_phone = [[CustomButton alloc] initWithFrame:CGRectMake(64, 50, 30, 54) withPerson:person];
    button_phone.tableCell = cell;
    button_phone.tag = 1;
    UIImage *image = [UIImage imageNamed:@\"friends.png\"];
    [button_phone setImage:image forState:UIControlStateNormal];
    [button_phone addTarget:self action:@selector(setIcon:) forControlEvents:UIControlEventTouchUpInside];
    [tmpView_setIcon addSubview:button_phone];
//    
    //smallicon-01按钮
    CustomButton *button_message = [[CustomButton alloc] initWithFrame:CGRectMake(128, 50, 30, 54) withPerson:person];
    button_message.tableCell = cell;
    button_message.tag = 2;
    UIImage *image2 = [UIImage imageNamed:@\"sweet.png\"];
    [button_message setImage:image2 forState:UIControlStateNormal];
    [button_message addTarget:self action:@selector(setIcon:) forControlEvents:UIControlEventTouchUpInside];
    [tmpView_setIcon addSubview:button_message];
//    
    //smallicon-02按钮
    CustomButton *button_message1 = [[CustomButton alloc] initWithFrame:CGRectMake(192, 50, 30, 54) withPerson:person];
    button_message1.tableCell = cell;
    button_message1.tag = 3;
    UIImage *image3 = [UIImage imageNamed:@\"class.png\"];
    [button_message1 setImage:image3 forState:UIControlStateNormal];
    [button_message1 addTarget:self action:@selector(setIcon:) forControlEvents:UIControlEventTouchUpInside];
    [tmpView_setIcon addSubview:button_message1];
//    
//    //smallicon-03按钮
    CustomButton *button_message3 = [[CustomButton alloc] initWithFrame:CGRectMake(256, 50, 30, 54) withPerson:person];
    button_message3.tableCell = cell;
    button_message3.tag = 3;
    UIImage *image4 = [UIImage imageNamed:@\"office.png\"];
    [button_message3 setImage:image4 forState:UIControlStateNormal];
    [button_message3 addTarget:self action:@selector(reloadMytableView) forControlEvents:UIControlEventTouchUpInside];
    [tmpView_setIcon addSubview:button_message3];
//    
    [tmpView setHidden:YES];
//    
    NSLog(@\"这里额图修改了2\");
//    
    tmpView_setIcon.tag = 2;
    [cell addSubview:tmpView_setIcon];
}

  • tableviewcell 子视图
发表于:2012-06-09 21:21

龙灵絮梦

荣誉:0 问题:2 回复:0
 
  • 对该问题进行补充

 

得到cell视图