0

我有一个 UIViewController 类 SurveyPanel,它像这样从 UIViewController 继承

SurveyPanel : UIViewController

然后我有另一个 UIViewController 类,称为 AnnouncementPanel,它继承自 SurveyPanel

AnnouncementPanel : SurveyPanel

我需要 AnnouncementPanel 来显示来自 SurveyPanel 的按钮和特定于 AnnouncementPanel 的按钮,但目前它只会显示 SurveyPanel 中的组件。这可能是我在 AppDelegate.cs 中加载控制器的方式吗?目前我正在做:

window = new UIWindow(UIScreen.MainScreenBounds);
AnnouncementPanel viewController = new AnnouncementPanel();
window.RootViewController = viewController;
window.MakeKeyAndVisible();
return true;
4

1 回答 1

0

您是通过加载 XIB 文件还是通过代码在视图中创建 UI?

如果“通过加载 XIB 文件”,使用带有 UIViewController 继承的准备好的 UI 会有点混乱。

如果“按代码”,请仔细检查您是否:

  1. 创建属于 AnnouncementPanel 的控件;
  2. 调用 AddSubview 向 AnnouncementPanel.View 添加控件;
  3. 正确设置控制框架(在屏幕的可见部分);
  4. 调用基(即SurveyPanel)控件的创建。

示例,我用于继承 (UITableViewCells) 视图:

// Base cell
public class UserCell: UIViewController
{

    string cellId = "CustomCell2";
    UITableViewCell cell;
    public UITableViewCell Cell {
        get { 
            if (cell == null)
                cell = new UITableViewCell (UITableViewCellStyle.Default, cellId);
            return cell; }
    }

    protected UIImageViewAvatar IvaAvatar;
    protected UILabel LblPerson;

    ...

    public UserCell (string cellId)
    {
        this.cellId = cellId;

        IvaAvatar = new UIImageViewAvatar ();
        LblPerson = new UILabel ();

        Cell.AddSubview (IvaAvatar);
        Cell.AddSubview (LblPerson);
    }

    ...

}

// Inherited cell
public class MessageCell: UserCell
{
    protected UILabel LblText;
    protected UILabel LblDatePlace;

    Message message;
    public Message Message {
        get { return message; } 
        set {
            message = value;
            Render ();
        }
    }

    ...

    // 4.
    // It is important to call base constructor
    public MessageCell (string cellId): base(cellId)
    {
        // 1.
        LblText = new UILabel ();
        LblDatePlace = new UILabel ();

        // 2.
        // Adding more controls to (Cell) View
        Cell.AddSubview (LblText);
        Cell.AddSubview (LblDatePlace);
    }

    ...

    // 3.
            // Render is called when someone set up Message property
    // So frames will be changed according to new data
    public new void Render()
    {
        base.Render();

        // Text
        LblText.Text = Message.Text;
        LblText.Font = UIFont.SystemFontOfSize (Constants.FONT_SIZE_MESSAGE);

        LblText.LineBreakMode = UILineBreakMode.WordWrap;
        LblText.Lines = 0;
        LblText.Frame = new RectangleF (LblPerson.Frame.Left, LblPerson.Frame.Bottom //+ Constants.SIZE_IDENT*/
                                        ,
                                        Cell.Frame.Width - LblPerson.Frame.Left - Constants.SIZE_IDENT, 0);
        LblText.SizeToFit ();

    }
}
于 2012-08-23T06:25:02.977 回答