简体   繁体   English

UITableView在iPad(ios7)上显示意外行:

[英]UITableView showing unexpected rows on iPad (ios7):

在此处输入图片说明

It had the first row and the third row that I don't want to show. 它有第一行和第三行,我不想显示。 I had found the same question but he(she) doesn't have the same problem with me, and I cannot solved the problem.With iPad(ios 6) it's work fine, but this bug happen on iPad(ios7).Here is my code: 我发现了相同的问题,但他(她)与我没有相同的问题,我无法解决问题。使用iPad(ios 6)可以正常工作,但此错误发生在iPad(ios7)上。我的代码:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return (calEnabled.boolValue ? 2 : 1);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
        return 1;

    if (calEnabled.boolValue) {
        return (reminderEnabled.boolValue ? 2 : 1);
    }

    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 || indexPath.row == 0) {
        return 44;
    }

    return 200;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tabView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CallSettingsTableViewCell* sourceCell = [tabView dequeueReusableCellWithIdentifier:@"VMSettingsTabCell_ID"];
    if (sourceCell == nil) {
        sourceCell = [[CallSettingsTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"VMSettingsTableCell_ID"];
    }

if (indexPath.section == 0)
{
    sourceCell.textLabel.text = calEnabled.title;
    sourceCell.accessoryView = calEnabled.ui_switch;
}
else if (indexPath.row == 0)
{
    sourceCell.textLabel.text = reminderEnabled.title;
    sourceCell.accessoryView = reminderEnabled.ui_switch;
}
else
{
    [sourceCell disableRightSwipe];
    sourceCell.textLabel.text = calReminder.title;
    sourceCell.accessoryView = calReminder.ui_picker;
}

sourceCell.accessoryType = UITableViewCellAccessoryNone;
sourceCell.selectionStyle = UITableViewCellSelectionStyleNone;

return sourceCell;
}

pleased help me to solve it. 很高兴帮助我解决它。 Thank in advance. 预先感谢。

Try adding the code below to remove the space between sections, or you can simply try using UITableViewStylePlain instead of UITableViewStyleGrouped. 尝试添加以下代码以删除各节之间的空格,或者您可以简单地尝试使用UITableViewStylePlain代替UITableViewStyleGrouped。

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001;
}


-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
}

change this 改变这个

  - (UITableViewCell *)tableView:(UITableView *)tabView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CallSettingsTableViewCell* sourceCell = [tabView dequeueReusableCellWithIdentifier:@"VMSettingsTabCell_ID"];
        if (sourceCell == nil) {
            sourceCell = [[CallSettingsTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"VMSettingsTableCell_ID"];
        }

    if (indexPath.row == 0)
    {
        sourceCell.textLabel.text = calEnabled.title;
        sourceCell.accessoryView = calEnabled.ui_switch;
    }
    else if (indexPath.row == 1)
    {
        sourceCell.textLabel.text = reminderEnabled.title;
        sourceCell.accessoryView = reminderEnabled.ui_switch;
    }
    else
    {
        [sourceCell disableRightSwipe];
        sourceCell.textLabel.text = calReminder.title;
        sourceCell.accessoryView = calReminder.ui_picker;
    }

    sourceCell.accessoryType = UITableViewCellAccessoryNone;
    sourceCell.selectionStyle = UITableViewCellSelectionStyleNone;

    return sourceCell;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM