2014-10-14 2 views
3

사용자 정의 테이블 셀 뷰를 만드는 데 문제가 있습니다.ios 8에서 xib 예외가 발생하는 사용자 정의 테이블 셀 뷰

CustomCell.h

#import <UIKit/UIKit.h> 

@interface CustomCell : UITableViewCell 
@property (weak, nonatomic) IBOutlet UIImageView *imageView; 
@property (weak, nonatomic) IBOutlet UILabel *date; 
@property (weak, nonatomic) IBOutlet UILabel *title; 
@property (weak, nonatomic) IBOutlet UILabel *content; 

@end 

CustomCell.m

#import "CustomCell.h" 

@implementation CustomCell 
@synthesize title, imageView, content, date; 
- (void)awakeFromNib { 
    // Initialization code 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

@end 

TableViewController

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

    static NSString *simpleTableIdentifier = @"CustomCell"; 
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:simpleTableIdentifier owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    cell.title.text = [titles objectAtIndex:indexPath.row]; 
    cell.imageView.image = [UIImage imageNamed:[images objectAtIndex:indexPath.row]]; 
    cell.content.text = [shortTexts objectAtIndex:indexPath.row]; 
    cell.date.text = [dates objectAtIndex:indexPath.row]; 
    return cell; 
} 

던져 예외

2014-10-14 19:06:59.290 pl.wroclaw.2017[7450:2962005] -[CustomCell _needsSetup]: unrecognized selector sent to instance 0x127d15bc0 
2014-10-14 19:06:59.291 pl.wroclaw.2017[7450:2962005] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomCell _needsSetup]: unrecognized selector sent to instance 0x127d15bc0' 
*** First throw call stack: 
(0x1871a2084 0x1977d80e4 0x1871a9094 0x1871a5e48 0x1870ab08c 0x18ba63c08 0x18bc1a3bc 0x18bc0efc4 0x18ba04c60 0x18b921874 0x18b279d58 0x18b274944 0x18b2747e8 0x18b273fe8 0x18b273d6c 0x18bbae7f0 0x18bbaf69c 0x18bbad820 0x18f3a5640 0x18715a360 0x187159468 0x187157668 0x187085664 0x18b98f500 0x18b98a4f8 0x1000b65a4 0x197e46a08) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

나는 xib를 제거하고 다시 추가하는 모든 것을 시도했다. 이전 프로젝트로 내 방법을 두 번 확인했는데 그냥 작동합니다. 이제는 새 프로젝트를 통해 문제가 해결되지 않았으며 해결책을 찾지 못했습니다. 이 "_needsSetup"에 대한 정보를 찾으려고했지만 아무 것도 찾을 수 없습니다.

도움 주셔서 감사합니다.

답변

4

도움이 될지 모르겠지만 xib 기반 셀을 사용하는 권장 방법은 nib를 cellForRowAtIndexPath :에로드하는 대신 nib을 등록하는 것입니다. 그래서, viewDidLoad에 넣어,

if (cell == nil) 절을 삭제하십시오.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
:이 방법으로 셀을 반환하는 것을 잊었다 때문에
10

나는 같은 오류가 있었다 그것은이었다
관련 문제