2010-01-21 2 views
2

다른 문제가 있습니다.UITableViewDelegate가 아닌 함수에서 UITableViewCell을 다시 사용하십시오.

내가 좋아하는 내 TableViewCells을 만드는 오전 : "Cell_0, 셀 1 등"당신이 볼로


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell; 
    UILabel *label = nil; 

    NSString *cellIdentifier = [NSString stringWithFormat:@"Cell_%i", indexPath.row]; 

    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease]; 
     //cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier]; 
     label = [[UILabel alloc] initWithFrame:CGRectZero]; 
     [label setLineBreakMode:UILineBreakModeWordWrap]; 
     [label setMinimumFontSize:FONT_SIZE]; 
     [label setNumberOfLines:0]; 
     [label setFont:[UIFont systemFontOfSize:FONT_SIZE]]; 
     [label setTag:1]; 


     [[cell contentView] addSubview:label]; 

    } 
return cell; 
} 

는, 내가 좋아하는 식별자와 세포를

하고있는 TableView 방법없는 기능에

, 나는이 셀을 식별자를 호출하여 사용하고 싶다. 나는 이것을 좋아한다 :


UITableViewCell *cell = [myTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]]; 
    } 
UILabel *label = (UILabel*)[cell viewWithTag:1]; 

캔트 나는 이것을 다음과 같이 사용한다?

내가 셀에있는 레이블의 색을 변경하려고하는데 액세스하려고 시도하지만 위선적입니다. 셀은 nil이 아니지만 label은 항상 nil입니다. 나는 어떻게해야합니까?

내가 원하는 셀인지 빈 셀인지 어떻게 알 수 있습니까?

답변

1

ok 배열의 모든 indexPath를 채우고 셀을 호출하는 동안 해당 배열에서 인덱스 경로를 호출하여 문제를 해결했습니다. 답변 주셔서 감사합니다

1

이것은 세포 재사용의 모든 목적을 이깁니다!

동일한 "외관"을 가진 (즉 동일한 하위보기가있는) 모든 셀에 동일한 셀 식별자를 사용하고 그 내용 만 변경해야합니다.

특정 행에 대해 만든 셀을 가져 오려면 [tableView cellForRowAtIndexPath:indexPath]을 사용하십시오.

+0

나는 내 문제를 잘 말할 수 없다고 생각합니다. 나는 getCellToBeModified라는 메서드를 가지고있다. 안에는 indexPath가 없습니다. 하지만이 방법으로 내 셀을 사용해야합니다. 그래서, 나는 가변 배열에 보유하고있는 내 CellIDS를 알고, 사용하여 해당 셀에 액세스하려고 : UITableViewCell * cell = [myTableView dequeueReusableCellWithIdentifier : [NSString stringWithFormat : @ "Cell_ % i", myCellID]]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithFrame : CGRectZero reuseIdentifier : [NSString stringWithFormat : @ "Cell_ % i", myCellID]]; } 위임 메서드를 사용하는 솔루션이 필요합니다. –

관련 문제