【问题标题】:Iphone sdk - Strange behaviour with UITableView and UITableViewCellAccessoryIphone sdk - UITableView 和 UITableViewCellAccessory 的奇怪行为
【发布时间】:2011-02-28 19:55:50
【问题描述】:

我在加载表格时遇到了奇怪的行为。

表格有时加载正常,有时加载 UITableViewCellAccessory's 添加到最后部分的某些行。

这是 cellForRowAtIndexPath 代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
NSString *enabled= @"1";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}


if(indexPath.section == 0)
{
    if(indexPath.row == 0)
    {
        cell.textLabel.text =[section1 objectAtIndex:0];
        cell.accessoryType = UITableViewCellAccessoryNone;
        return cell;


    }
}       
if(indexPath.section == 1)
{
    if(indexPath.row == 0)
    {
        cell.textLabel.text =[section2 objectAtIndex:0];
        cell.accessoryType = UITableViewCellAccessoryNone;
        return cell;


    }
}       


if(indexPath.section == 2)
{
    if(indexPath.row == 0)
    {
        cell.textLabel.text =[NSString stringWithFormat:@"Morning Time: %@" , [section3 objectAtIndex:0]];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        return cell;


    }
    if(indexPath.row == 1)
    {
        cell.textLabel.text =[NSString stringWithFormat:@"Afternoon Time: %@" , [section3 objectAtIndex:1]];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        return cell;

    }
}

if(indexPath.section == 3)
{

    if(indexPath.row == 0)
    {
        cell.textLabel.text =@"Monday";

        if([enabled isEqualToString:[section4 objectAtIndex:0]]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        return cell;



    }
    if(indexPath.row == 1)
    {
        cell.textLabel.text =@"Tuesday";

        if([enabled isEqualToString:[section4 objectAtIndex:1]]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        return cell;


    }
    if(indexPath.row == 2)
    {
        cell.textLabel.text =@"Wednesday";

        if([enabled isEqualToString:[section4 objectAtIndex:2]]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            }
        return cell;


    }
    if(indexPath.row == 3)
    {
        cell.textLabel.text =@"Thursday";

        if([enabled isEqualToString:[section4 objectAtIndex:3]]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            }
        return cell;



    }
    if(indexPath.row == 4)
    {
        cell.textLabel.text =@"Friday";

        if([enabled isEqualToString:[section4 objectAtIndex:4]]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            }
        return cell;



    }
    if(indexPath.row == 5)
    {
        cell.textLabel.text =@"Saturday";

        if([enabled isEqualToString:[section4 objectAtIndex:5]]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
        return cell;



    }
    if(indexPath.row == 6)
    {
        cell.textLabel.text =@"Sunday";

        if([enabled isEqualToString:[section4 objectAtIndex:6]]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        return cell;



    }


}   
return cell;

}

最后一行有一个UITableViewCellAccessoryDe​​tailDisclosureButton,但是我从来没有设置这个按钮到这个部分,随机出现:

谢谢

【问题讨论】:

    标签: iphone cocoa-touch uikit uitableview


    【解决方案1】:

    您将获得一个以前用于第 2 部分的回收单元,因此有一个披露按钮。由于您仅在启用日期时更改 accessoryType,因此如果未启用披露按钮,则永远不会删除它。

    解决此问题的最简单方法是:

    cell.accessoryType = UITableViewCellAccessoryNone;
    

    在您出列/创建单元格之后。

    【讨论】:

      猜你喜欢
      • 2013-02-09
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多