0
爲什麼我在iPad上的UITableView中看不到任何文本?UITableView顯示,但單元格中沒有任何名稱
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
if(tableView != nil)
[tableView reloadData];
}
- (void)viewDidLoad {
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024) style:UITableViewStylePlain];
tableView.delegate = self;
[self.view addSubview:tableView];
}
- (void)doneButtonSelected:(id)sender {
[self dismissModalViewControllerAnimated:NO];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0)
return 1;
else if(section == 1)
return 2;
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
int section = indexPath.section, row = indexPath.row;
if(section == 0) {
if(row == 0)
cell.textLabel.text = @"YAY";
}
else if(section == 1) {
if(row == 0)
cell.textLabel.text = @"BLACH";
else if(row == 1)
cell.textLabel.text = @"GAH";
}
return cell;
}
- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[theTableView deselectRowAtIndexPath:indexPath animated:YES];
int section = indexPath.section, row = indexPath.row;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0)
return @"Blah";
else if(section == 1)
return @"Hi";
return @"Hello!";
}
@end
你看到一個空白表視圖,或根本沒有?節標題顯示了嗎? – 2012-07-27 20:46:45