2014-07-23 2 views
0

나는 사용자 정의 테이블 셀에 길게 누르면에 서브 뷰을 추가하지만, 오전에 반환 할 사라에 사용자 정의 테이블 셀에 하위 뷰를 추가 내가 표를 스크롤 할 때, 하위보기가 사라집니다..테이블의 스크롤 하위 뷰가 무엇인지 그 서브 뷰가 다시 세포

내가 다시 스크롤 할 때, 그 서브 뷰는 여전히 쇼/해당 셀 또는 다른 말로를 나타 난 을 선택된 상태로 유지 말할 수 있도록 어떻게해야합니까?

- (IBAction)click4:(id)sender 
{ 
    // 
    self.lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
    [self.lpgr setMinimumPressDuration:1]; 
    [self.contentView addGestureRecognizer:self.lpgr]; 
} 
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender 
{ 
    if ([sender isEqual:self.lpgr]) { 
     if (sender.state == UIGestureRecognizerStateBegan) 
     { 
      self.actionButtonView = [[PerformAction alloc]initWithNibName:@"PerformAction" bundle:Nil]; 
      [self.thirdImageView addSubview:self.actionButtonView.view]; 
     } 
    } 
} 

답변

1

모든 것이 예상대로 작동합니다. 당신이 dequeueReusableCellWithIdentifier에 도달하면 설계로

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self cellIdentifierForIndexPath:indexPath] forIndexPath:indexPath]; 
    id item = [self itemAtIndexPath:indexPath]; 
    // some configuration here. 
    return cell; 
} 

그래서 당신이 세포를 펜촉에 (또는 스토리 보드에) : 나는 당신에게이 같은 cellForRowAtIndexPath 일을 생각한다.

수행하려는 작업을 수행하려면보기를 추가하고 셀 상태에 따라보기를 숨길 수 있습니다. 긴 탭으로이 상태를 업데이트하십시오.

0

초기화 식별자 UITableViewCell은 별도의 식별자입니다. 그러면 UITableView에있는 모든 셀이로드되고 UITableView을 스크롤하면 그대로 유지됩니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

NSString *cellIdentifier = [NSString stringWithFormat:@"CellIdentifier%d%d",indexPath.section,indexPath.row]; 
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: cellIdentifier]; 
if (cell == nil) 
{ 
    cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: cellIdentifier]; 
} 
return cell; 
} 

그러나 모든 셀이 UITableView에로드되어 있기 때문에 더 많은 메모리를 소비합니다.

관련 문제