내 코드에 간단한 중대한 문제가 있습니다.UITableviewcell의 UIButton 숨기기
내 Tableview에서 내 편집 단추 (네비게이션 바에 있음)를 눌렀을 때 UITableview의 편집 방법이 필요합니다. 내 셀에있는 단추와 레이블을 숨기려고합니다.
코드 :
나는이처럼 내 버튼을 추가하고 ..
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *currentCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
currentCell = nil;
if (currentCell==nil)
{
currentCell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
BtnEmail=[UIButton buttonWithType:UIButtonTypeCustom];
//BtnEmail = (UIButton *)[currentCell viewWithTag: 3];
BtnEmail.frame=CGRectMake(265, 17, 25, 25);
BtnEmail.tag=indexPath.row;
//[BtnEmail setTitle:@"E-mail" forState:UIControlStateNormal];
[BtnEmail setBackgroundImage:[UIImage imageNamed:@"email.png"] forState:UIControlStateNormal];
[BtnEmail addTarget:self action:@selector(BtnEmail:) forControlEvents:UIControlEventTouchUpInside];
[currentCell.contentView addSubview:BtnEmail];
[currentCell.contentView bringSubviewToFront:BtnEmail];
return currentCell;
}
내 편집 버튼이
편집 버튼과 같이 선언한다 :
self.navigationItem.rightBarButtonItem = self.editButtonItem;
및 편집에 내 방법을 클릭하십시오를 클릭하십시오.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[listTableView setEditing:editing animated:animated];
if(editing)
{
self.navigationItem.leftBarButtonItem.enabled = NO;
//BtnEmail.frame=CGRectMake(355, 17, 25, 25);
BtnEmail.hidden = TRUE;
}
else
{
self.navigationItem.leftBarButtonItem.enabled = YES;
//BtnEmail.frame=CGRectMake(265, 17, 25, 25);
BtnEmail.hidden = FALSE;
}
[super setEditing:editing animated:animated];
}
이 경우에는 마지막 셀 Button과 Lable 모두를 숨길 것입니다. 내 셀의 모든 UIButton을 숨겨야합니다.
나는 테이블에 3 셀을 가지고 경우 다음은 마지막으로 버튼을 숨길처럼 만 ..
감사합니다. 이 경우 마지막 할당 된 버튼을 cellForRowAtIndexPath
방법이다
BtnEmail.hidden = FALSE;
를 선언하기 때문이다
이 경우 BtnEmail에 대한 마지막으로 생성 된 참조가 표시되기 때문입니다. – Exploring