인 경우 간단한 문제가 있지만 이해가되지 않습니다. tableView
을 포함하는 UIView
(SecondView
)을로드하는 UIViewControler
(RootController
)이 있습니다. 문제는 UIView
이 numberOfSectionsInTableView
과 numberOfRowsInSection
을 호출하지만 cellForRowAtIndexPath
을 호출하지 않으며 테이블 뷰가 표시되지 않는다는 것입니다. RootViewController
의 코드는 다음과 같습니다cellForRowAtIndexPath가 호출되지 않았지만 numberOfRowsInSection이라는 숫자가
SecondView *secondView = [[seconddView alloc] initWithFrame:CGRectMake(0, 60, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:secondView];
그리고 SecondView
의 코드는 다음과 같습니다
@interface SecondView() <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic,retain) UITableView *table;
@end
@implementation SecondView
@synthesize table;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.table = [[UITableView alloc] init];
self.table.delegate = self;
self.table.dataSource = self;
[self addSubview:self.table];
}
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Prova";
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
당신은 나에게 문제를 찾는 데 도움이 될 수 있습니까? 고맙습니다.
테이블 뷰 프레임이란 무엇입니까? – Wain
이전 답변으로 해결되었지만 실제 설명은 다음과 같습니다. [http : // stackoverflow.COM/질문/7712325가/cellforrowatindexpath이--호출되지] [1] [1] : http://stackoverflow.com/questions/7712325/cellforrowatindexpath-not-called – GrandSteph
정답이 여기에있다은 https ://stackoverflow.com/questions/7712325/cellforrowatindexpath-not-called – Ramis