2012-06-13 2 views
3

각 행에 대해 두 개의 UILabel이있는 TableView를 사용했습니다. 셀의 사용자 슬쩍, 나는이 문제를 해결하기 위해, 내 휴대폰에 첫 번째 레이블의 프레임을 감소하고자하는 경우 :editingStyleForRowAtIndexPath가 동시에 세 번 호출되었습니다. 왜?

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NO] autorelease]; 
    } 

    custom_cell = [[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 45)] autorelease]; 


    custom_cell.textColor = [UIColor blackColor]; 

    custom_cell.backgroundColor = [UIColor clearColor]; 

    [custom_cell setText:[[self.Notes objectAtIndex:indexPath.row ]objectForKey:@"Text"]]; 

    [cell.contentView addSubview:custom_cell]; 

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
    [dateFormat setDateFormat: @"dd MMM yy"]; 

    [dateFormat setLocale:[NSLocale currentLocale]]; 

    NSDate *dateTmp = [[self.Notes objectAtIndex:indexPath.row] objectForKey:@"CDate"]; 

    cell.detailTextLabel.text = [dateFormat stringFromDate: dateTmp]; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    [dateFormat release]; 

    return cell; 


} 
: 이것은 내 코드

bug_image

입니다

는 그런 내 휴대폰에 첫 번째 레이블의 프레임을 줄이기 위해,이 코드를 작성했습니다 :

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSLog(@"row=%d", indexPath.row); 

    custom_cell.frame = CGRectMake(10, 0, 150, 45); 

    return UITableViewCellEditingStyleDelete; 
} 

결과는 부분적으로 올바른 것입니다. 내 tableView의 마지막 레이블은 항상 축소 된 것이지 올바른 것이 아닙니다.

또한 콘솔은 NSLog 메시지를 세 번 인쇄합니다. 왜?

2012-06-13 22:07:34.809 myVoyager[1935:16103] row=0 
2012-06-13 22:07:34.810 myVoyager[1935:16103] row=0 
2012-06-13 22:07:34.813 myVoyager[1935:16103] row=0 

감사합니다, (내 영어 죄송합니다!) 피사에서 알레산드로

답변

1

나는 피사에서 발레를 해요!

UITableViewCell *myCell = [self.tableView cellForRowAtIndexPath:indexPath]; 

를 다음 셀에 프레임을 설정합니다 당신은 당신의 editingStyleForRowAtIndexPath 방법으로 다음과 같이해야한다.

+0

안녕하세요 발레리오, 도와 주셔서 감사합니다. 나는 같은 문제를 겪었다. 'editingStyleForRowAtIndexPath' 메소드는 이전 콘솔 메시지에서 볼 수있는 것과 동시에 3 번 호출됩니다. 그래서 프레임을 세 번 연속으로 줄입니다. 나는 이것을 기대하지 않는다. 왜? 도와 주셔서 감사합니다. – AlexM

+0

첫 번째 사항 : 셀을 할당 할 때 셀 식별자를 사용해야합니다. 그렇지 않으면 "dequeue"메서드를 사용하여 스택에서 재사용 된 셀을 가져 오는 것이 무의미합니다. 그런 다음 각 셀에 적합하지 않은 메모리와 계산이 필요하기 때문에 dateformatter에 인스턴스 변수를 사용하고 한 번 설정하십시오. 반복되는 문제에 대해 테이블에 몇 개의 섹션과 행이 있습니까? – Valerio

관련 문제