2012-03-06 5 views
-1

레이블 및 텍스트 필드가 포함 된 사용자 지정 셀을 만들었습니다. 테이블보기에서이 사용자 지정 셀을 사용하고 있습니다. 내가 텍스트 필드에 데이터를 입력하고 내가 스크롤 할 때 내 데이터가 대체되고 있습니다. 모든 스크롤은 대체/지워집니다. 아무도 내가 실수를하고있는 곳을 말해줍니다. 내 맞춤 셀 코드가 여기에옵니다. 감사합니다.테이블보기에서 사용자 지정 셀을 다시 사용할 수 있습니까

-(UITableViewCell *)returnCellForEach:(UITableView *)tableView 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier"]; 
    if (cell == nil) 
    { 
     [[NSBundle mainBundle] loadNibNamed:@"CustomCellToAddDetails" owner:self options:nil]; 
     cell = customCell; 
//  customCell = nil; 
     customLabel = (UILabel *)[customCell.contentView viewWithTag:100]; 
    } 
    return cell; 
} 

-(UITextField *)dataField 
{ 
    UITextField *textField = customField; 

    return textField; 
} 
+0

와 함께이 라인

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier"]; 

을 대체 않았다있어? – jrturton

+0

@jrturton : 이것은 내 사용자 지정 메서드입니다 .i 사용자 지정 셀에 대해 만들었습니다. – Kiran

+0

_ 어디에서 전화하고 있습니까? cellForRowAtIndexPath 메서드는 어디에 있습니까? – jrturton

답변

0

당신은 사용자가 어딘가에 특정 indexpath 관련된 데이터 입력을 저장해야합니다 그리고 당신은 세포를 스크롤 할 때 먼저 거기 indexpath에 해당하는 모든 데이터 객체이며, 그에 따라 데이터를 설정 여부를 확인해야합니다. 사전을 사용하여 특정 셀에 해당하는 데이터를 저장할 수 있습니다. 있습니다

클래스가 QRTYPECELL 전화를 따르고, 그것은

+0

감사! 사실 나는 데이터베이스와 함께 작동하는 Birthday Remainder Application을하고 있습니다.이 모든 텍스트 필드 값을 데이터베이스에 저장하고 있습니다. 다시 내가 사전을 사용하면 데이터베이스에 데이터를 저장하는 데 문제가 발생합니까? – Kiran

+0

NO issues, 당신은 안전하게 데이터베이스를 사용할 수 있지만 tableview를 사용하여 테이블 셀을 스크롤 할 때 사전을 사용하여 임시로 데이터를 저장하면됩니다. 나중에이 데이터를 데이터베이스에 저장하고 그에 따라 가져올 수 있습니다. –

0

난 당신이 내가있는 tableview 클래스 외부에있는 사용자 정의 테이블 뷰 셀 클래스를 만드는 데 필요한 내 경우에 사용하는 방법 이름에 익숙하지 않다 도움이되기를 바랍니다 관련 코드 다음의 TableView 클래스에서

@implementation QRTypeCell 
@synthesize imageView; 
@synthesize labelview; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
if (self) { 
    // Initialization code 
    imageView = nil; 
    labelview= nil; 
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,30,30)]; 
    imageView.contentMode = UIViewContentModeCenter; 
    [self.contentView addSubview:imageView]; 
    self.contentView.backgroundColor = [UIColor blackColor]; 


    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; 
    label.textColor = [UIColor greenColor]; 
    label.backgroundColor = [UIColor blackColor]; 

    label.font = [UIFont systemFontOfSize:17]; 
    self.labelview = label; 
    [self.contentView addSubview:label]; 


} 
return self;} 

: 그리고 IB에

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

QRTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[QRTypeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];} 
    CurrentQRCode = (QRCode *)[fetchedResultsController objectAtIndexPath:indexPath]; 
    NSString *icon = CurrentQRCode.parsed_icon; 
    NSString *string = CurrentQRCode.parsed_string; 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;  
    NSString *filePath = [[NSBundle mainBundle] pathForResource:icon ofType:@"png"]; 
    UIImage *image_file = [UIImage imageWithContentsOfFile:filePath]; 
+0

: 내 질문에 대답 해주세요. 당신은 내 질문에 맞지 않을 것입니다. 당신은 탁자에 대한 대답을하고 있습니다. 그리고 제 질문의 부분이 다릅니다. 도움을 주셔서 감사합니다! – Kiran

0

당신이 점에서 식별자 필드 장소 어떤 가치를 것을 사용 발 재사용 식별자로 사용하십시오. 나는 이것이 당신을 도울 것이라고 생각합니다. `당신이에서 호출됩니다

+0

: 전에 그랬어요. 그리고 변화가 없습니다. – Kiran

+0

당신은 같은 이름을 @ "Identifier"에 둘 다 – hchouhan02

+0

둘 다요? 맞춤 셀 IB에만 넣었습니다. 맞춤 셀에만 맞춰서 재사용하고 있습니다. 다른 곳을 아직도 사용해야합니까? – Kiran

0

확인 난 당신이 customCell을위한 클래스를 생성하고`returnCellForEach은 무엇입니까

CustomCell *customCell=(CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
관련 문제