我在設置UITableView時發生了一個奇怪的錯誤。發生什麼事是當我第一次點擊它時什麼也沒有發生(它應該改變一個UIView),但是當我點擊上面或下面的一個單元格時,它就會變成我想要顯示的UIView。我創建它就像我創建的每個其他tableview,這裏是代碼:奇怪的UITableView錯誤
- (void)viewDidLoad {
[super viewDidLoad];
TableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320.0,120.0)];
// Table View is an iVar in the header file
TableView.dataSource = self;
TableView.delegate = self;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* CellIdentifier = @"CELLIDENTIFIER";
UITableViewCell* cell = [TableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
[cell setBackgroundView:[[GMCellBackground alloc] init]];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
}
The TeachingsCellIdentifier是一個錯字。我遺漏了切換UIViews的代碼,但我確實在 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath –
有同樣的錯誤,我即將發佈的問題,但這是第一個寫這個問題時的建議。 – user2387149