[英]UITableView and Cell showing content on wrong place
我的表格视图有两个问题,即,当尚未到达表格视图的末尾时,(在屏幕中间)显示来自表格页脚视图的“返回首页”按钮。 如您在第一张图片中所看到的,主页按钮出现在屏幕中间,这是我不想要的。 它必须留在表格的底部。
我的第二个问题是分段控件,该控件通常位于视图顶部,正在我的一个单元格中重新出现,它不属于该单元格。 我确保已禁用单元格reusidentifier。
单元格中只填充了文本,所以我看不到为什么出现了分段控件。
编辑:添加代码
填充单元格的代码:(只是其中的一部分,但这只是另一个单元格中的其他文本,没有任何变化)
if(indexPath.section == 2){
[[cell textLabel] setTextAlignment:UITextAlignmentLeft];
[[cell textLabel] setText:_actor.actorBeschrijving];
if([[cell textLabel] text] == nil)
{
[[cell textLabel] setText:@"Druk om een beschrijving toe te voegen"];
[[cell textLabel] setTextColor:[UIColor grayColor]];
}
}
if(indexPath.section == 3 && control.selectedSegmentIndex == 1){
if([has count] == 0){
[[cell textLabel] setTextAlignment:UITextAlignmentLeft];
[[cell textLabel] setText: @"Voeg een nieuw object toe"];
}
else{
if(indexPath.row < [has count]){
AnObject *object = (AnObject*)[has objectAtIndex:indexPath.row];
[[cell textLabel] setTextAlignment:UITextAlignmentLeft];
[[cell textLabel] setText:object.objectNaam];
}
if(indexPath.row == [has count]){
[[cell textLabel] setTextAlignment:UITextAlignmentLeft];
[[cell textLabel] setText:@"Voeg een nieuw object toe"];
}
}
}
if(indexPath.section == 3 && control.selectedSegmentIndex == 3){
if([isResponsible count] == 0){
[[cell textLabel] setTextAlignment:UITextAlignmentLeft];
[[cell textLabel] setText: @"Voeg een nieuwe goal toe"];
}
else{
if(indexPath.row < [isResponsible count]) {
Goal *goal = (Goal*)[isResponsible objectAtIndex:indexPath.row];
[[cell textLabel] setText:goal.goalNaam];
}
if(indexPath.row == [isResponsible count]){
[[cell textLabel] setTextAlignment:UITextAlignmentLeft];
[[cell textLabel] setText: @"Voeg een nieuwe goal toe"];
}
}
}
页脚代码:
@property (nonatomic, retain) IBOutlet UIView *myFooterView;
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if(section == tableView.numberOfSections - 1)
return 50.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if(myFooterView == nil) {
//allocate the view if it doesn't exist yet
myFooterView = [[UIView alloc] init];
//create the button
UIButton *footButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[footButton setFrame:CGRectMake(110, 10, 100, 30)];
//set title, font size and font color
[footButton setTitle:@"Go Home" forState:UIControlStateNormal];
[footButton.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
//set action of the button
[footButton addTarget:self action:@selector(clickPressed:)
forControlEvents:UIControlEventTouchUpInside];
//add the button to the view
[myFooterView addSubview:footButton];
}
//return the view for the footer
return myFooterView;
}
额外的注释:我在只有一个部分的不同视图(不同的表视图)中使用相同的页脚,并且此处的按钮显示正确。
嘿,您可以动态地为分段控件和按钮编写代码,而不是将其置为静态代码。
例如
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.section == 0)
{
if (indexPath.row == 0)
{
//Dynamic Code for Segmented Control
[cell.contentView addSubview:segementedControl];
}
}
-----------
if (indexPath.section == 4) // For Eg. 5 is the last section. You can use your own
{
if (indexPath.row == 0)
{
//Dynamic Code for Button
[cell.contentView addSubview:button];
}
}
}
希望它会工作。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.