1

所以我最近决定加入 iOS 开发,主要是因为我喜欢跨多个平台扩展我的知识,而且我已经了解 java 并编写了一个 android 应用程序,iOS 是下一步。

所以我的问题是:在一个表中,我使用自定义表源来响应单击一行并加载新视图。现在在该视图中,我想添加一个后退按钮以返回上一个视图。

   PointF locationOne = new PointF (5, 5);
    PointF locationTwo = new PointF (5, 100);
    SizeF size = new SizeF (120, 40);

    RectangleF tView = new RectangleF (locationOne, size);
    RectangleF tView2 = new RectangleF (locationTwo, size);
        UILabel l1 = new UILabel(){Text = "LOOL",Frame=tView};

        UIButton backbutton = new UIButton(){
            Frame=tView2
        };
        backbutton.Frame = tView2;
        backbutton.TitleLabel.Text = "Zurueck";
        backbutton.Hidden = false;

        UIView previousview = viewController.View;
        backbutton.TouchDown += (sender, e) => { 
            viewController.View = previousview;
        };

        UIView v = new UIView();
        v.AddSubview(l1);
        v.AddSubview (backbutton);


        viewController.View = v;

这将是我现在的代码。标签正在显示,按钮没有。有什么我想念的吗?

已经谢谢了:)

4

1 回答 1

1

UIView v没有框架。您需要将其设置为父控制器的框架(也许v.Frame = viewController.View.Frame;)。然后,换出 的视图viewcontroller

编辑:

UIButton 的初始化不对。以下是创建常规按钮的方法:

PointF locationOne = new PointF (5, 5);
PointF locationTwo = new PointF (5, 100);
SizeF size = new SizeF (120, 40);

RectangleF tView = new RectangleF (locationOne, size);
RectangleF tView2 = new RectangleF (locationTwo, size);
UILabel l1 = new UILabel (){Text = "LOOL",Frame=tView};

UIButton backbutton = UIButton.FromType(UIButtonType.RoundedRect);
backbutton.Frame = tView2;
backbutton.SetTitle("Zurueck", UIControlState.Normal);

UIView previousview = viewController.View;
backbutton.TouchUpInside += (sender, e) => { 
    viewController.View = previousview;
};

UIView v = new UIView ();
v.BackgroundColor = UIColor.White;
v.AddSubview (l1);
v.AddSubview (backbutton);
viewController.View = v;
于 2012-08-26T12:13:40.490 回答