滚动更多时间时,UiTbleview Cell Overlapping

时间:2015-06-20 04:44:54

标签: ios objective-c uitableview cell

我正在使用array(2) { [1]=> string(5) "abcde" [2]=> string(4) "pqrs" } 在视图中显示不同的数据。我正在使用.m文件中的代码创建的UITableView。它们共有9种不同类型的细胞,具有0种不同的标识符和细胞高度。当表格中有两个不同高度的同一个单元格开始相互重叠时。

这里我将代码放入单元格方法的高度。

UITableViewCell

行代码的单元格

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row ==0)
    {
        return 120.0;
    }
    else{
        //For Action User follow
        if(condition)
        {
            //Checking if the Follow is shared or not
            if()
            {
                //Checking the number of Counts
                if()
                {
                    if()
                    {
                        if()
                        {
                            return  340.0+(arTemp1.count*50.0);
                        }
                        else
                        {
                            return  157.0+(arTemp1.count*50.0);
                        }
                    }
                    else
                    {
                        if()
                        {
                            return  340.0+200;
                        }
                        else
                        {
                            return  157.0+200;
                        }
                    }
                }
                else
                {
                    if( )
                    {
                        return 340.0f;
                    }
                    else{
                        return 157.0f;
                    }
                }
            }
            else
            {
                if(arTemp1.count>0)
                {
                    if(arTemp1.count <4)
                    {
                        if()
                        {
                            height=height+150;
                        }
                        return  height+(arTemp1.count*50.0);
                    }
                    else
                    {
                        if( )
                        {
                            height= height;
                        }
                        return  height;
                    }
                }
                else
                {
                    if()
                    {
                        height= height+40;
                    }
                    return height;
                }
            }
        }
        else if ()
        {
            if(arTemp1.count>0)
            {
                if(arTemp1.count <4)
                {
                    return  160.0+(arTemp1.count*50.0);
                }
                else
                {
                    return  160.0+200;
                }
            }
            else
            {
                return 150.0f;
            }
        }
        //For Action Add New Reciepe
        else if ()
        {
            if(arTemp1.count>0)
            {
                if(arTemp1.count <4)
                {
                    return  420.0+(arTemp1.count*50.0);
                }
                else
                {
                    return  420.0+200;
                }
            }
            else
            {
                return 400.0f;
            }
        }
        else if ()
        {
            if(arTemp1.count>0)
            {
                if(arTemp1.count <4)
                {
                    return  350.0+(arTemp1.count*50.0);
                }
                else
                {
                    return  350.0+200;
                }
            }
            else
            {
                return 350.0f;
            }
        }
        //For Action Added new page
        else if ()
        {
            if(arTemp1.count>0)
            {
                if(arTemp1.count <4)
                {
                    return  350.0+(arTemp1.count*50.0);
                }
                else
                {
                    return  350.0+200;
                }
            }
            else
            {
                return 350.0f;
            }
        }
        else if ()
        {
            if(arTemp1.count>0)
            {
                if(arTemp1.count <4)
                {
                    return  170.0+(arTemp1.count*50.0);
                }
                else
                {
                    return  150.0+200;
                }
            }
            else
            {
                return 150.0f;
            }
        }
        //For Action Add Photo
        else if ()
        {
            if(arTemp1.count>0)
            {
                if(arTemp1.count <4)
                {
                    return  350.0+(arTemp1.count*50.0);
                }
                else
                {
                    return  350.0+200;
                }
            }
            else
            {
                return 350.0f;
            }
        }
    }
    return 0.0f;
}

2 个答案:

答案 0 :(得分:1)

试试这个

首先使用tableView

注册您的单元类
<div id="gameScreen">
    <img src="image/logo.png" />
    <br />
    <hr />
     <h3>You will play 10 rounds against the computer and I'll keep score!<br /><br />


    Wins: <span id="wins">0</span>
    <br />
    Losses: <span id="losses">0</span>
    <br />
    Ties: <span id="ties">0</span>
    <br />
    <br />


    Current Game: <br /><br />
    <span id="whoWon">

    </span> 
    <br /><br />
    You've got
    <span id="triesLeft"></span>
    tries left!
    <br />
    <br />

    <br />

    Select your weapon!<br /><br />

    <img src="image/rock1.jpg" name="rock" onclick ="playGame('rock');" onmouseover="over(0)" onmouseout="out(0)">
    <img src="image/paper1.jpg" name="paper" onclick ="playGame('paper');" onmouseover="over(1)" onmouseout="out(1)">
    <img src="image/scissors1.jpg" name="scissors" onclick ="playGame('scissors');" onmouseover="over(2)" onmouseout="out(2)">
        <br/>
        <span id="result"></span>
        <img id="imageResult"/>
    </h3> 

答案 1 :(得分:0)

您正在创建单元格并仅在其为零时标记它,iOS会重复使用单元格,因此您需要每次都配置单元格。

    NSString *CellIdentifier = @"a";

    UITableViewCell *a = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (a == nil)
    {
        //Follow Cell Initializing
        a = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        a.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    a.tag=a;

    //Create Cell Method
    [self aCreateCell:a atIndexPath:indexPath];

    // Set Cell Method
    [self aSetCell:a atIndexPath:indexPath];
    [a setClipsToBounds:YES];
    return a;