2013-07-22 20 views
0

我想在主视图上创建一个子视图。我想使用视图,但意见混淆层

在此子视图中添加web视图和退出按钮。

我通过创建一个圆圈和一个标签通过视图创建退出按钮图像。

下面是我的代码,我的按钮操作即退出按钮的功能不能执行。

这是什么问题?对于同一个按钮上一个动作

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
if (self) { 


    self.frame = CGRectMake(0, 0, 1024, 768); 

    [self setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.8]]; 


    UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(8,20,40,40)]; 
    circleView.alpha = 0.5; 
    circleView.layer.cornerRadius = 20; 
    //self.circleView.backgroundColor = [UIColor blueColor]; 


    circleView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1]; 
    circleView.layer.borderColor = [[UIColor blackColor] CGColor]; 
    circleView.layer.borderWidth = 5; 

    UILabel* circleIndex = [[UILabel alloc] init]; 
    circleIndex.frame = CGRectMake(13, 10, 25, 20); 
    [circleIndex setFont:[UIFont fontWithName:@"Arial-BoldMT" size:22]]; 
    [circleIndex setText:@"x"]; 

    [circleView addSubview:circleIndex]; 




    UIView *alertView = [[UIView alloc]initWithFrame:CGRectMake(40, 80, 944, 600)]; 

    UIWebView* webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 944, 600)]; 

    NSString *[email protected]"http://www.google.com"; 
    NSURL *nsurl=[NSURL URLWithString:url]; 
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; 
    [webView loadRequest:nsrequest]; 


    [alertView addSubview:webView]; 

    UIButton *exit = [[UIButton alloc]init]; 
    exit.frame = CGRectMake(920, -40, 38, 38); 
    [exit addTarget:self action:@selector(exitTheWebView) forControlEvents:(UIControlEventTouchUpInside)]; 
    [exit addTarget:self action:@selector(exitTheAlert) forControlEvents:(UIControlEventTouchUpInside)]; 
    [exit setBackgroundColor:[UIColor redColor]]; 

    // exit setBackgroundImage:<#(UIImage *)#> forState:<#(UIControlState)#> 

    [circleView addSubview:exit]; 

    [alertView addSubview:circleView]; 


    [self addSubview:alertView]; 

} 
return self; 
} 



-(void)exitTheWebView{ 

[self removeFromSuperview]; 

NSLog(@"bitch"); 
[self release]; 


} 

回答

0
[exit addTarget:self action:@selector(exitTheWebView) forControlEvents:(UIControlEventTouchUpInside)]; 
[exit addTarget:self action:@selector(exitTheAlert) forControlEvents:(UIControlEventTouchUpInside)]; 

两种方法,第一种方法将不会执行,因为第二个重写的第一个动作

+0

这只是一个错误,我忘了删除该行。它不是实际的问题 – erdemgc

0

要添加到像相同的按钮操作:

[exit addTarget:self action:@selector(exitTheWebView) forControlEvents:(UIControlEventTouchUpInside)]; 
[exit addTarget:self action:@selector(exitTheAlert) forControlEvents:(UIControlEventTouchUpInside)]; 

所以它会在你点击它时调用第二个动作。手段(exitTheAlert

那个按钮的代码也变更为:

UIButton *exits = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
exits.frame = GRectMake(920, -40, 38, 38);; 
exits addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside]; 
[circleView addSubview:exits]; 
[circleView bringSubviewToFront:exits] 
[circleView setUserInteractionEnabled:YES]; 

注:exit是一个在建的关键字,所以不要使用关键字的变量/对象。

+0

问题是实际上一个图层问题,一些视图是在彼此的顶部,防止处理的行动。但我无法弄清楚。 – erdemgc

+0

@erdemgc:添加说明,请立即检查 –