2013-08-16 11 views
0

레이블과 imageView가있는 사용자 정의 셀을 만들었으므로 사용자 정의 셀 셀에는 CustomTableCell 식별자가있는 customCellClass 클래스가 있습니다. 이, 데이터가 전달되지 않은 결과 스크린 샷입니다하지만 u는CustomCell : 기본보기에서 데이터를 표시 할 수 없습니다.

screen shot

이 메신저 배열 * 이름에서 데이터를 얻는하는 .m 파일입니다을 볼 수있는 사용자 정의 테이블이 나타납니다. 내가 무엇을 놓치고 있는지보십시오. btw im [self.tableView reloadData] 시도 중입니다. viewdidload에서하지만 난 y를 몰라,하지만 난 그럴 수없는 시작.

@synthesize name = _name; 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    self.name = [NSArray arrayWithObjects:@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third", nil]; 
// self.name = [[NSArray alloc]initWithObjects:@"First", @"Second", @"Third", nil]; 


} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [self.name count]; 

} 

-(void) viewDidAppear:(BOOL)animated{ 

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 1; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *CellIdentifier = @"CustomTableCell"; 


    customCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    if (cell == nil) { 

     NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    cell.nameLabel.text = [self.name objectAtIndex:indexPath.row]; 
    cell.imageThumb.image = [UIImage imageNamed:@"images.jpeg"]; 
    return cell; 


} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 78; 
} 


@end 

은 BTW이

enter image description here

+1

헥타르 델리게이트와 데이터 소스를 테이블에 할당 했습니까 ?? –

+0

datacource 및 delegate ......? –

+0

콘센트 연결이 정확한가요? –

답변

2

그냥 그렇게 :

customCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
      NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil]; 
      cell = [nib objectAtIndex:0]; 
     } 
+0

메신저에서이 예외가 발생했습니다. 캐치되지 않은 예외 'NSInternalInconsistencyException'로 인해 앱이 종료됩니다. 이유 : '번들로 NIB를로드 할 수 없습니다 :'NSBundle (로드 됨) '이름과 함께'CustomTableCell '' –

+0

그래서 yuor 셀을로드하지 않으려 고하기 전에! – Leta0n

+0

사용자 정의 셀 이름 확인 – Leta0n

1

당신은이를 시도 할 수 있습니다 사용하여 사용자 정의 테이블 셀 메신저입니다 :

클래스는 다음과 같이 파일 만들기 :

CustomRankingCell.h

#import <UIKit/UIKit.h> 

@interface CustomRankingCell : UITableViewCell 

+(UITableViewCell *) cellFromNibNamed:(NSString *)nibName; 

@end 

#import "CustomRankingCell.h" 

@implementation CustomRankingCell 



+ (CustomRankingCell *)cellFromNibNamed:(NSString *)nibName { 

    NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:NULL]; 
    NSEnumerator *nibEnumerator = [nibContents objectEnumerator]; 
    CustomRankingCell *xibBasedCell = nil; 
    NSObject* nibItem = nil; 

    while ((nibItem = [nibEnumerator nextObject]) != nil) { 
     if ([nibItem isKindOfClass:[CustomRankingCell class]]) { 
      xibBasedCell = (CustomRankingCell *)nibItem; 
      break; // we have a winner 
     } 
    } 

    return xibBasedCell; 
} 


@end 

그리고이

#import "CustomRankingCell.h" 

@interface RankingCell : CustomRankingCell 
{ 

} 

처럼 CustomRankingCell보다는있는 UITableViewCell하여 사용자 정의 셀을 확장 한 다음과 같이 정의 셀을 사용 CustomRankingCell.m :

static NSString *CellIdentifier = @"RankingCell"; 

RankingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
{ 
    cell = (RankingCell *)[RankingCell cellFromNibNamed:@"RankingCell"]; 
} 

희망은 그것을 돕는다!!

+0

과 똑같은 결과입니다. 대답도 고맙습니다. –

+0

수정 된 코드대로 시도하십시오. 그것은 분명히 작동합니다 .. –

0

이것은 내가 테이블에서 내 사용자 정의 셀에 사용했던 것이며 완벽하게 작동합니다. 당신은 alloc init을하고 다음이 if

cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    if (cell == nil) { 

     NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

을 통과하지 않을 경우에는 ... 전무에 확인

static NSString *CellIdentifier = @"CustomTableCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
0
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.name count]; 
} 


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 


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

    mycustomcell *cell = (mycustomcell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"mycustomcell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
     NSLog(@"NIB = %@",nib); 
     NSLog(@"Cell = %@",cell); 
    } 

    cell.txtData.text=[NSString stringWithFormat:@"%@",[self objectAtIndex:indexPath.row]]; 

      cell.imgThumb.image = [UIImage imageNamed:@"images.jpeg"]; 
      cell.txtData.enabled=NO; 


    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    return cell; 
} 

이 시도 당신을위한 희망 도움말 ..

+0

왜 그냥 코드 ... 설명이 없으면? – Leta0n

+0

여기 mucustomecell은 customecell 구현이며 텍스트 필드 "txtData"대신 레이블 "name"으로 데이터를 가져올 수 있습니다. –

+0

이것은 방금 구현 한 코드입니다. 단 [셀 setSelectionStyle : UITableViewCellSelectionStyleNone]; 누락 된 것이지만 역시 시도 할 것입니다 –

관련 문제