所以我最近决定加入iOS开发,主要是因为我喜欢在多个平台上扩展我的知识,而且我已经知道java并编写了一个Android应用程序,iOS是下一步。
所以我的问题是: 在一个表中,我使用自定义tablesource来响应行上的点击并加载新视图。现在在该视图中,我想添加一个后退按钮以返回上一个视图。
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;
这将是我现在的代码。正在显示标签,按钮不是。有什么我想念的吗?
非常感谢:)
答案 0 :(得分: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;