ios - tableView 添加额外的(空)单元格

标签 ios uitableview xamarin.ios

我正在开发一个 iOS 应用程序,它在 UITableView 中显示 session 。我目前正处于开发自定义 tableviewcell 来表示我的数据的阶段。

根据事件类型,我正在更改 tableviewcell 中小条的背景颜色(蓝色或橙色)。由于某种原因,着色关闭,并且表格 View 添加了另一个不应添加的单元格。请参见下图。

enter image description here

注意第一个单元格..它的类型是:“ISKE”所以应该是橙色,这是正确的。请注意第二个单元格的类型:“ISKA”。现在右边的栏应该是蓝色的,但显然不是。但这很奇怪,因为日期的字体颜色是正确的。另请注意显示的最后一个栏,同时没有可用的额外单元格。

我不知道为什么会发生这种情况。我希望有人能指出我正确的方向。 我的获取单元格方法如下:

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
    Session session = ObjectModel.Current.AllSessions.ElementAt (indexPath.Row);

    SessionTableViewCell cell = tableView.DequeueReusableCell (session.SessionEvent.EventTitle) as SessionTableViewCell;

    if (cell == null) 
    {
        cell = new SessionTableViewCell ();
        var views = NSBundle.MainBundle.LoadNib ("SessionTableViewCell", cell, null);
        cell = Runtime.GetNSObject (views.ValueAt (0)) as SessionTableViewCell;
    }

    if (session.SessionEvent.EventTitle == "ISKE") {
        cell.SessionEventColor = UIColor.FromRGB (255, 165, 0);
        cell.SessionDateFontColor = UIColor.FromRGB (255, 165, 0);
    } else {
        cell.SessionEventColor = UIColor.FromRGB (80, 124, 191);
        cell.SessionDateFontColor = UIColor.FromRGB (80, 124, 191);
    }

    cell.SessionDay = session.SessionDate.DayOfWeek.ToString ().ToUpper ();
    cell.SessionTime = session.SessionDate.ToString ("HH:mm");
    cell.SessionDate = session.SessionDate.Day.ToString ().ToUpper ();
    cell.SessionSpeaker = "testspeaker";
    cell.ImgBgView.Layer.BorderColor = UIColor.FromRGB (206, 206, 208).CGColor;
    cell.ImgBgView.Layer.BorderWidth = 1.0f;

    cell.SelectionStyle = UITableViewCellSelectionStyle.None;
    cell.SessionTitle = session.SessionTitle;
    cell.SessionEvent = session.SessionEvent.EventTitle;
    cell.SessionRoom = session.SessionRoom;

    return cell;
}

最佳答案

检查您的数据源、指定的 UITableView 高度和单元格高度。

关于ios - tableView 添加额外的(空)单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18826434/

相关文章:

iphone - 在 Iphone SDK 的导航栏上添加多个按钮

ios - 无法将 UIView 定位到 TableView 的底部

ios - UITableViewHeaderFooterView* header =[self.tableView headerViewForSection :0];

iphone - 在 UITableView 上添加 UISearchBar

c# - 单点触控的 iOS map

ios - 适用于企业应用程序的 Apple 应用程序传输安全 (ATS)

ios - 从 UITableViewCell 中删除除 imageView 之外的所有 subview

ios - 无法将数据追加到 NSMutableData 中,出现段错误 11

ios - 从 UITableViewCell 到 DetailViewController 的 segue 不起作用

c# - 如何将长文本放入 UITextView 或 UILabel