2014-12-26 3 views
-2

내 표보기 셀로 사용하려는 xib가있는 UITableViewCell의 하위 클래스가 있습니다. 셀 단위로 셀의 속성을 수정해야합니다. 여기 내 코드가있다. NSLog는 속성이 올바르게 변경되었음을 보여 주지만, 앱을 실행하면 usernameLabel이 xib 파일의 자리 표시 자와 동일하게 유지됩니다. 도움과 행복한 축하에 감사드립니다.UITableViewCell이 속성을 수정하지 않습니다.

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

static NSString *simpleTableIdentifier = @"SimpleTableItem"; 

    // ActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
LiveCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil) { 
    // Load the top-level objects from the custom cell XIB. 
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LiveCell" owner:self options:nil]; 
    // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain). 
    cell = [topLevelObjects objectAtIndex:0]; 
} 
if (dataLoaded == YES) { 
    cell.usernameLabel = [[UILabel alloc] init]; 

    NSLog(@"Data Cell Loaded"); 
    PFObject *liveObject = [tableData objectAtIndex:indexPath.row]; 
    cell.usernameLabel.text= liveObject[@"Name"]; 
    NSLog(@"Name Label: %@", cell.usernameLabel.text); 

    return cell; 
} 
else { 
    return cell; 
} 

}

+0

'cell.usernameLabel = [[UILabel alloc] init]'은 비현실적입니다. –

답변

2

이 코드 고려해

cell.usernameLabel = [[UILabel alloc] init]; 
NSLog(@"Data Cell Loaded"); 
PFObject *liveObject = [tableData objectAtIndex:indexPath.row]; 
cell.usernameLabel.text= liveObject[@"Name"]; 
NSLog(@"Name Label: %@", cell.usernameLabel.text); 
return cell; 

라벨을 만들어 그 텍스트를 설정,하지만 그래서 뭐? 셀의 인터페이스에 절대 넣지 마십시오. 그래서 레이블이 생겨나고 텍스트가 설정되고 연기가 나면 사라집니다.

이미 셀이 인 경우 해당 인터페이스에 a usernameLabel이있는 경우 인터페이스에없는 새 셀로 바꾸는 것이 잘못되었습니다. usernameLabel이 아직없는 경우이 인터페이스를 인터페이스에 추가해야합니다. 어느 쪽이든,이 코드는 바보입니다.

+0

어떻게 해결할 수 있습니까? usernameLabel이 각 셀에 있어야하지만 텍스트를 변경해야합니다. – Team6Labs

+0

이미 셀에'usernameLabel'이 있습니까? 'usernameLabel'이 콘센트를 통해 이미 가리 킵니까? 그렇다면 첫 번째 줄을 삭제하십시오. 모든 행은 콘센트를 종료합니다. xib 파일에이 모든 것을 설정 한 다음 그 한 줄로 망가 뜨리고 있습니다. – matt

+0

개체가 어떻게 인스턴스화되는지 이해하고 있습니까? 이 레이블을 _twice_ - 먼저 xib (양호)에서로드 한 다음 코드에서 작성한 완전히 새로운 레이블 (불량)로 교체하여이 레이블을 인스턴스화합니다. – matt

관련 문제