locked
how to remove seprator line RRS feed

  • Question

  • User306227 posted

    I m using default separator line .how to remove separator line top of the first cell and how to add separator line for particular cell


    Tuesday, June 23, 2020 3:33 PM

All replies

  • User395091 posted

    You want to remove the separator line below the Navigation Bar of IOS?

    Tuesday, June 23, 2020 3:35 PM
  • User306227 posted

    No for every header view separator line should remove in xamarin. Ios native

    Tuesday, June 23, 2020 4:33 PM
  • User382871 posted

    how to remove separator line top of the first cell and how to add separator line for particular cell Cell doesn't provide a method to remove the separator line. But we could add the line to a cell para. Therefore, try to remove the separator lines of all cells, and then add lines for the desired cells.

    Hide the separator lines in ViewDidLoad method of viewController class ``` public override void ViewDidLoad() { base.ViewDidLoad(); ...

    var tableView = new UITableView(new CoreGraphics.CGRect(0, 0, width, height));
    tableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
    
    ...
    

    } Create a custom `UITableViewCell` to achieve the function. public class MyCell : UITableViewCell { public MyCell(IntPtr p) : base(p) { }

    public MyCell(UITableViewCellStyle style, string reuseIdentifier) : base(style, reuseIdentifier)
    {
        UILabel label = new UILabel();
        label.Frame = new CGRect(0, 0, UIApplication.SharedApplication.KeyWindow.Bounds.Size.Width, this.Frame.Size.Height - 3);
    
        UIView uIView = new UIView() { Frame = new CGRect(0, 0, UIApplication.SharedApplication.KeyWindow.Bounds.Size.Width, 3) };
        uIView.BackgroundColor = UIColor.Black;
    
        this.Add(label);
        this.Add(uIView);
    }
    

    } Use custom `UITableViewCell` to display the separator line. public class CustomUITableViewSource : UITableViewSource { ... public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { if (indexPath.Row == 0) { MyCell myCell = new MyCell(UITableViewCellStyle.Default, cellIdentifier); ... return myCell; } else { UITableViewCell cell = new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier); ... return cell; } } } ```

    Wednesday, June 24, 2020 3:09 AM
  • User306227 posted

    This is my code __ i need to use default cell only .i need separator line for only section 2 and section 4

    if (indexPath.Section == 0) { var incidentCell = incidentPreviewTableView.DequeueReusableCell(StudentDetailCell.Key) as StudentDetailCell; incidentCell.SelectionStyle = UITableViewCellSelectionStyle.None; incidentCell.SetParent(this); incidentCell.SeparatorInset.InsetRect(new CGRect(0, 0, 0, 0)); incidentCell.UpdatePreviewIncidentCell(indexPath, GetPreviewDetails);

                    incidentCell.SeparatorInset = new UIEdgeInsets(0, 11111111110, 0, 0);
    
    
                    cell = incidentCell;
    
                }
                else if (indexPath.Section == 1)
                {
                    cell = tableView.DequeueReusableCell("IncidentDateCell");
    
                    if (cell == null)
                    {
                        cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "IncidentDateCell");
                    }
                    cell.TextLabel.Text = "Jan 10, 2020";
                    cell.TextLabel.Lines = 0;
                    cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                    cell.TextLabel.Font = UIFont.SystemFontOfSize(17, UIFontWeight.Regular);
                    cell.TextLabel.TextColor = AppConstants.StudTabBarBGColor;
                    cell.SeparatorInset = UIEdgeInsets.Zero;
                    // cell.SeparatorInset = new UIEdgeInsets(0, 0, 0, 0);
                    cell.TextLabel.TextAlignment = UITextAlignment.Left;
                }
                else if (indexPath.Section == 2)
                {
                    cell = tableView.DequeueReusableCell("IncidentActionCell");
    
                    if (cell == null)
                    {
                        cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "IncidentActionCell");
                    }
                    if (GetPreviewDetails[0].Actions.Count == 0 || GetPreviewDetails[0].Actions == null)
                    {
                        noRecordBGView.Hidden = false;
                        noRecordLabel.Hidden = false;
                        noRecordBGView.BackgroundColor = AppConstants.BackGroundRedikerTeal;
                        cell.SeparatorInset = UIEdgeInsets.Zero;
                        cell.ContentView.AddSubview(NoRecordFound(indexPath));
    
                    }
                    else
                    {
                        cell.TextLabel.Text = GetPreviewDetails[0].Actions[indexPath.Row].ActionName;
                        cell.TextLabel.Lines = 0;
                        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        cell.TextLabel.Font = UIFont.SystemFontOfSize(17, UIFontWeight.Regular);
                        cell.TextLabel.TextColor = AppConstants.StudTabBarBGColor;
                        cell.DetailTextLabel.Text = "Jan 10, 2020";
                        cell.DetailTextLabel.Font = UIFont.SystemFontOfSize(14, UIFontWeight.Regular);
                        cell.DetailTextLabel.TextColor = AppConstants.GrayTextColor;
                        cell.DetailTextLabel.Lines = 0;
                        cell.DetailTextLabel.LineBreakMode = UILineBreakMode.WordWrap;
    
                         cell.SeparatorInset = new UIEdgeInsets(0, cell.Bounds.Bottom - 35, 0, 0);
    
    
    
                        noRecordBGView.Hidden = true;
                        noRecordLabel.Hidden = true;
    
                    }
                }
    
                else if (indexPath.Section == 3)
                {
                    if (GetPreviewDetails[0].TeacherLists.Count == 0 || GetPreviewDetails[0].TeacherLists == null)
                    {
                        cell = tableView.DequeueReusableCell("IncidentTeacherCell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "IncidentTeacherCell");
                        }
                        noRecordBGView.Hidden = false;
                        noRecordLabel.Hidden = false;
                        cell.SeparatorInset = UIEdgeInsets.Zero;
                        cell.ContentView.AddSubview(NoRecordFound(indexPath));
                       // cell.SeparatorInset = UIEdgeInsets.Zero;
                    }
                    else
                    {
                        noRecordBGView.Hidden = true;
                        noRecordLabel.Hidden = true;
                        var incidentCell = incidentPreviewTableView.DequeueReusableCell(StudentDetailCell.Key) as StudentDetailCell;
                        incidentCell.SelectionStyle = UITableViewCellSelectionStyle.None;
                        incidentCell.SetParent(this);
                        incidentCell.UpdatePreviewIncidentCell(indexPath, GetPreviewDetails);
                        noRecordBGView.BackgroundColor = AppConstants.BackGroundRedikerTeal;
                        cell = incidentCell;
                        cell.SeparatorInset = new UIEdgeInsets(0, 0, 1, 0);
                    }
                }
                else if (indexPath.Section == 4)
                {
                    cell = tableView.DequeueReusableCell("IncidentPlaceCell");
    
                    if (cell == null)
                    {
                        cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "IncidentPlaceCell");
                    }
                    if (GetPreviewDetails[0].PlaceLists.Count == 0 || GetPreviewDetails[0].PlaceLists == null)
                    {
                        noRecordBGView.Hidden = false;
                        noRecordLabel.Hidden = false;
                        cell.SeparatorInset = UIEdgeInsets.Zero;
                        cell.ContentView.AddSubview(NoRecordFound(indexPath));
    
    }
                    else
                    {
                        cell.TextLabel.Text = GetPreviewDetails[0].PlaceLists[indexPath.Row].PlaceName;
                        cell.TextLabel.Lines = 0;
                        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        cell.TextLabel.Font = UIFont.SystemFontOfSize(17, UIFontWeight.Regular);
                        cell.TextLabel.TextColor = AppConstants.StudTabBarBGColor;
                        cell.TextLabel.TextAlignment = UITextAlignment.Left;
                        //  cell.SeparatorInset = new UIEdgeInsets(0, 0, 1, 0);
                        var width = incidentPreviewTableView.Frame.Width;
                        var headerTxt = GetPreviewDetails[0].PlaceLists[indexPath.Row].PlaceName;
    
                        var tableWidth = width - 10;
                        var headerTextHeight = CommonHelper.GetLabelSize(headerTxt, tableWidth, float.MaxValue,
                                       UIFont.SystemFontOfSize(17, UIFontWeight.Regular)).Height;
    
                        var rowHeight = 10 + headerTextHeight + 10;
                        var bottomBorder = new CALayer();
                        bottomBorder.Frame = new CGRect(x: 10.0f, y: rowHeight - 1, width: incidentPreviewTableView.Frame.Width, height: 1.0);
                        bottomBorder.BackgroundColor = AppConstants.CourseGradeSectionBGColor.CGColor;
                        cell.ContentView.Layer.AddSublayer(bottomBorder);
                        noRecordBGView.Hidden = true;
                        noRecordLabel.Hidden = true;
                    }
                }
                else if (indexPath.Section == 5)
                {
                    cell = tableView.DequeueReusableCell("IncidentCommentCell");
    
                    if (cell == null)
                    {
                        cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "IncidentCommentCell");
                    }
                    if (GetPreviewDetails[0].Comment == "" || GetPreviewDetails[0].Comment == null)
                    {
                        noRecordBGView.Hidden = false;
                        noRecordLabel.Hidden = false;
                        cell.SeparatorInset = UIEdgeInsets.Zero;
                        noRecordLabel.Text = NSBundle.MainBundle.GetLocalizedString(AppConstants.CommentEmptyLkey, "");
                        cell.ContentView.AddSubview(NoRecordFound(indexPath));
    
                    }
                    else
                    {
                        noRecordBGView.Hidden = true;
                        noRecordLabel.Hidden = true;
                        cell.SelectionStyle = UITableViewCellSelectionStyle.None;
                        cell.TextLabel.Text = GetPreviewDetails[0].Comment;
                        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        cell.TextLabel.Lines = 0;
                        cell.TextLabel.TextColor = AppConstants.StudTabBarBGColor;
                        cell.TextLabel.Font = UIFont.SystemFontOfSize(17, UIFontWeight.Regular);
                        cell.TextLabel.TextAlignment = UITextAlignment.Left;
                        cell.SeparatorInset = new UIEdgeInsets(0, 10, 1, 0);
    
                }
                else if (indexPath.Section == 6)
                {
    
                    if (GetPreviewDetails[0].ImageLists.Count == 0 || GetPreviewDetails[0].ImageLists == null)
                    {
                        cell = tableView.DequeueReusableCell("IncidentPictureCell");
    
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "IncidentPictureCell");
                        }
                        noRecordBGView = new UIView
                        {
                            Frame = new CGRect(12, 12, incidentPreviewTableView.Frame.Width - 20, 36),
                            BackgroundColor = AppConstants.BackGroundRedikerTeal
                        };
                        noRecordBGView.Layer.CornerRadius = 5;
                        noRecordBGView.ClipsToBounds = true;
                        noRecordLabel = new UILabel
                        {
                            Frame = new CGRect(10, 0, 200, 36),
                            TextColor = AppConstants.GrayTextColor,
                            Font = UIFont.SystemFontOfSize(14, UIFontWeight.Regular),
                            TextAlignment = UITextAlignment.Left,
                            BackgroundColor = UIColor.Clear
                        };
                        noRecordBGView.AddSubview(noRecordLabel);
                        noRecordBGView.Hidden = false;
                        noRecordLabel.Hidden = false;
                        noRecordLabel.Text = NSBundle.MainBundle.GetLocalizedString(AppConstants.PictureEmptyImagekey, "");
                        cell.SeparatorInset = UIEdgeInsets.Zero;
                        cell.ContentView.AddSubview(noRecordBGView);
                      //  cell.SeparatorInset = new UIEdgeInsets(0, 0, 0, 0);
                    }
                    else
                    {
                        var incidentCell = incidentPreviewTableView.DequeueReusableCell(PicturesCell.Key) as PicturesCell;
                        incidentCell.SelectionStyle = UITableViewCellSelectionStyle.None;
                        incidentCell.SetParent1(this);
                        incidentCell.UpdatePreviewPictureCell(true, GetPreviewDetails);
                        cell = incidentCell;
                        noRecordBGView.Hidden = true;
                        noRecordLabel.Hidden = true;
                      //  cell.SeparatorInset = new UIEdgeInsets(0, 0, 0, 0);
                    }
                }
    
    Wednesday, June 24, 2020 4:14 AM
  • User382871 posted

    i need to use default cell only .i need separator line for only section 2 and section 4 To add the separator line to a defalut cell, try to add an UIView to the cell directly in GetCell method. ``` public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { UITableViewCell cell = new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier);

    if (indexPath.Row == 2 || indexPath.Row == 4)
    {
        UILabel label = cell.TextLabel;
    
        UIView uIView = new UIView() { Frame = new CGRect(0, label.Bounds.Size.Height, UIApplication.SharedApplication.KeyWindow.Bounds.Size.Width, 3) };
        uIView.BackgroundColor = UIColor.Black;
    
        cell.Add(uIView);
    }
    
    return cell;
    

    } ```

    Wednesday, June 24, 2020 6:49 AM