그래서 (.xib 파일을 사용하여) 사용자 정의 셀을 작성하고 사용자 정의 컨트롤러 클래스를 사용하여 링크했으며 셀 식별자를 쓰는 것을 잊지 않았습니다. 나는 또한 내 테이블보기 컨트롤러 프로토 타입 셀에 동일한 셀 식별자를 부여했습니다. 사용자 정의 셀 컨트롤러 클래스에서 나는 단지 .h 파일의 텍스트 레이블에 콘센트가 있습니다. 아래는 내 테이블보기 컨트롤러의 코드입니다. 앱을 실행하면 사용자 정의 셀은 표시되지 않지만 셀을 클릭 할 수 있기 때문에 거기에 셀이 있습니다 (그러나 셀은 흰색 임). 무엇이 잘못 되었나요? 맞춤 셀이 표시되지 않는 이유는 무엇입니까?사용자 정의 셀이 표시되지 않습니다.
사용자 정의가 아닌 기본 셀을 사용하면 모든 것이 정상적으로 작동합니다. 그래서 문제는 제가 어딘가에 내 사용자 정의 셀을 사용하지 않는다는 것입니다.
#import "ListmaniaTableViewController.h"
#import "ListmaniaTableViewCell.h"
@interface ListmaniaTableViewController()
@property (strong, nonatomic) NSMutableArray *tasks; //of task object
@end
@implementation ListmaniaTableViewController
- (void)viewDidLoad{
[super viewDidLoad];
task *task1 = [[task alloc] init];
task1.taskDescription = @"TASK 1";
[self.tasks addObject:task1];
task *task2 = [[task alloc] init];
task2.taskDescription = @"TASK 2";
[self.tasks addObject:task2];
task *task3 = [[task alloc] init];
task3.taskDescription = @"TASK 3";
[self.tasks addObject:task3];
}
- (NSMutableArray *)tasks{
if(!_tasks){
_tasks = [[NSMutableArray alloc] init];
}
return _tasks;
}
/*- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}*/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"Add New Item"]) {
}
}
- (void)addNewTask:(task *)newTask{
[self.tasks addObject:newTask];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.tasks count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ListmaniaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListmaniaCell" forIndexPath:indexPath];
if(!cell){
[tableView registerNib:[UINib nibWithNibName:@"ListmaniaTableViewCell" bundle:nil] forCellReuseIdentifier:@"ListmaniaCell"];
cell = [tableView dequeueReusableCellWithIdentifier:@"ListmaniaCell" forIndexPath:indexPath];
}
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(ListmaniaTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
task *task = [self.tasks objectAtIndex:indexPath.row];
NSString *taskLabel = task.taskDescription;
cell.taskLabel.text = taskLabel;
}
@end
내가 할 때 아무것도 (난 그냥 다시 시도하고 변화 없음) – crazyshark