2012-07-03 3 views
0

UILabel의 서브 클래스 인 WishInfoTextView를 가진 사용자 정의 UITableViewCell이 있습니다.사용자 정의 UITableViewCell이 중복되지 않게하기

static NSString *CellIdentifier = @"Cell"; 
NSMutableDictionary* item = [myWishes objectAtIndex: indexPath.row]; 

WishTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; 
if(cell == nil) { 
    cell = [[WishTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    [cell setSelectionStyle: UITableViewCellEditingStyleNone]; 
    [cell setWishInfo: item]; 
}  

WishInfoTextView* infoText = (WishInfoTextView*)[cell viewWithTag: kTableInfoText]; 
infoText.text = [item objectForKey:@"name"]; 

NSLog(@"\nTaggedText: %@\nNormalText: %@", infoText.wishName, [item objectForKey:@"name"]); 

문제는 내가 중복 된 셀을 가지고 있다는 것입니다. 나는 태그를 설정하는 것에 대해 읽었습니다. 하지만 태그로 내 라벨에 액세스하면 아무 것도 변경되지 않습니다.

답변

1

셀을 원할 때마다 [email protected]"name"을 사용하고 있습니다. 그래서 당신은 항상 똑같은 것을 얻을 것입니다. 문자열 배열이있는 경우 실제로는 다른 값을 얻기 위해 [arrayName objectAtIndex:indexPath.row]과 같은 것을 사용하십시오. 예를 들어

, I 배열에서 테이블을 채울 때 제가

NSArray *nameSection = [appD.data objectForKey:key]; 
cell.textLabel.text = [nameSection objectAtIndex:indexPath.row]; 

appD.data

Primary.plist

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>First type</key> 
    <array> 
     <string>object1</string> 
     <string>object2</string> 
     <string>object3</string> 
    </array> 
    <key>Second type</key> 
    <array> 
     <string>thing1</string> 
     <string>thing2</string> 
     <string>thing3</string> 
    </array> 
</dict> 
</plist> 
+0

정적는 NSString * CellIdentifier = @이다

NSString *DataPath = [Path stringByAppendingPathComponent:@"Primary.plist"]; NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:DataPath]; 

의해 입수되고 사용 "세포"; NSMutableDictionary * item = [myWishes objectAtIndex : indexPath.row]; 죄송합니다.이 부분은 코드 블록에서 제외되었습니다. 그래서 그게 문제가 아니야 – reapertjuh

+0

그게 네가 쓰고있는거야? 그것은 모두 귀하의 plist의 구조에 따라 달라집니다 – Dustin

+0

내 예제에서 반대 순서 때문에 – Dustin

관련 문제