【发布时间】:2012-06-02 01:09:39
【问题描述】:
我希望我的 tableView 显示包含文本的 6 行,在本例中为“示例”。据我所知,我的numberOfSectionsInTableView: 和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 行的行?
【问题讨论】:
-
这是所有普通表格视图的默认行为,其行数少于滚动所需的行数,因此仅设置行数和节数无济于事。你需要找到另一种方式......
标签: iphone objective-c ios uitableview