我希望我的tableView能顯示6行文本,本例中爲「Example」。據我所知,我有我的numberOfSectionsInTableView:
和numberOfRowsInSection:
正確設置。請參閱下面的示例代碼:UITableView顯示的行數多於numberOfRowsInSection中指定的行數:
- (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 6;
}
- (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 = @"Example";
return cell;
}
問題是當您看到下面的圖像顯示行不應該/不存在的行時。
如何擺脫過去顯示6行的行嗎?
這是比需要滾動更少的行所有普通表視圖的默認行爲,所以只需設置行數和部分的數量將無濟於事。你需要找到另一種方式... – BoltClock