簡體   English   中英

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

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

在此處輸入圖片說明

它有第一行和第三行,我不想顯示。 我發現了相同的問題,但他(她)與我沒有相同的問題,我無法解決問題。使用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;
}

很高興幫助我解決它。 預先感謝。

嘗試添加以下代碼以刪除各節之間的空格,或者您可以簡單地嘗試使用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];
}

改變這個

  - (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