Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIViewController内部的UIView还是更好的方法?_Objective C_Ios_Uiview_Uiviewcontroller_Uiview Hierarchy - Fatal编程技术网

Objective c UIViewController内部的UIView还是更好的方法?

Objective c UIViewController内部的UIView还是更好的方法?,objective-c,ios,uiview,uiviewcontroller,uiview-hierarchy,Objective C,Ios,Uiview,Uiviewcontroller,Uiview Hierarchy,我有一个问题,关于如何正确地做某种行动 下图显示了UIViewController,但视图的第二部分是自定义UIView(带有profile pic、name和Show view按钮的部分)。 子类UIView是使用以下代码分配的: profileView = [[GPProfileView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)]; profileView.myTripGradi

我有一个问题,关于如何正确地做某种行动

下图显示了UIViewController,但视图的第二部分是自定义UIView(带有profile pic、name和Show view按钮的部分)。 子类UIView是使用以下代码分配的:

    profileView = [[GPProfileView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];
    profileView.myTripGradientColor = YES;
    [self.view addSubview:profileView];
当然,问题是UIView上的按钮不能显示任何视图,因为只有UIViewController可以将另一个ViewController推送到窗口(正确吗?)

UIView在应用程序中的多个位置使用,需要轻松添加,并且在整个应用程序中具有相同的行为

在我添加按钮之前,这一切都很好,我开始认为我弄错了,必须有更好的方法来做到这一点(也许将UIView更改为其他方式?)

我想我应该可以打电话:

self.superview
然后以某种方式获取ViewController,这样我就可以将另一个ViewController推到视图层次结构中,但没有

有没有关于如何正确操作的建议和提示

更新: 我不知道如何从按钮按下另一个UIViewController

按下UIView中的按钮时,在此方法中应执行什么操作:

- (void) showViewButtonTouched:(UIButton*)sender {
GPProfileSocialFriendsViewController *friendsSettings = [[GPProfileSocialFriendsViewController alloc] init];

}
如何推送GPProfileSocialFriendsViewController


我认为您可以在UIViewController上的GPProfileView中创建弱引用。像这样:

@property (weak, nonatomic) UIViewController *rootController;
创建GPProfileView时,分配rootController属性:

profileView = [[GPProfileView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];
profileView.myTripGradientColor = YES;
profileView.rootController = self;   // if view created in view controller
[self.view addSubview:profileView];
在按钮选择器的实现中:

self.rootController push... // or pop
这可能不正确,但您可以尝试您的
-(void)showView按钮touched:(UIButton*)sender
方法应该在您的控制器中,最好将其命名为
-(void)showView:(UIButton*)sender
-(void)showProfile:(UIButton*)sender
,因此它清楚地指示了它的功能(而不是您是如何实现的)

视图不负责管理从一个状态到另一个状态的转换。如果您将方法移动到控制器,问题就不再存在了(您可以轻松访问
self.navigationController
,如果您没有这样的导航控制器,则可以直接推送:


[自我呈现视图控制器:需要按下的VCA动画:是完成:无]

按下按钮时,您可以让视图控制器按下下一个视图控制器。视图控制器可以在按钮上添加一个目标/操作,以便在内部事件润色时调用视图控制器中的操作方法。

由于没有人回复,我想我不是唯一一个不理解您的问题的人问题是该按钮无法按下其他视图控制器。我将更新我的问题。这可能是我问题的最佳问题。但我真的想让它更具动态性,因此我不必在每个使用UIView的Viewcontroller上定义选择器方法。但这可能是另一个问题。谢谢:-)