2011-07-12 10 views
1

アプリで作業し、次のコードを使用して:アプリはブックマークボタンを初めて実行されたときは、タップに応答するが、私はビューコントローラをプッシュするならば、それはだ戻って行くことはありませんいくつかの理由についてUIButtonが応答しません。どうして?

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    dataSource = [[NSArray alloc] initWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"stories.plist"]]; 

    contentsHeaderImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ContentsHeader.png"]] autorelease]; 
    [contentsHeaderImageView setFrame:CGRectMake(0, 0, 320, 131)]; 
    [contentsHeaderImageView setUserInteractionEnabled:YES]; 
    [self.view addSubview:contentsHeaderImageView]; 

    UITableView *tableView = [[[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(contentsHeaderImageView.frame), self.view.frame.size.width, self.view.frame.size.height - CGRectGetMaxY(contentsHeaderImageView.frame))] autorelease]; 
    [tableView setDelegate:self]; 
    [tableView setDataSource:self]; 
    [tableView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth]; 
    [tableView setContentInset:UIEdgeInsetsMake(1, 0, 1, 0)]; 
    [tableView setSeparatorColor:[UIColor whiteColor]]; 

    [self.view addSubview:tableView]; 

    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]]; 
    [tableView setBackgroundColor:[UIColor clearColor]]; 


    UIImageView *newView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fade.png"]] autorelease]; 
    [newView setFrame:CGRectMake(0, -20, 320, 69)]; 
    [self.view addSubview:newView]; 


    splashImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]] autorelease]; 
    [splashImage setFrame:CGRectMake(0, -20, 320, 480)]; 
    [self.view addSubview:splashImage]; 

    [self performSelector:@selector(animateOutSplashImage:) withObject:splashImage afterDelay:3]; 

} 

-(void)drawBookmarkButton 
{ 
    if (self.bookmarkButton) { 
     [self.bookmarkButton removeFromSuperview]; 
    } 
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"bookmark"]) { 
     self.bookmarkButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.bookmarkButton setImage:[UIImage imageNamed:@"bookmark 1.png"] forState:UIControlStateNormal]; 
     [contentsHeaderImageView addSubview:self.bookmarkButton]; 
     [self.bookmarkButton addTarget:self action:@selector(bookmarkButtonTapped) forControlEvents:UIControlEventTouchUpInside]; 
     [self.bookmarkButton setFrame:CGRectMake(260, 0, 50, 35)]; 


     //UITapGestureRecognizer *gr = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bookmarkButtonTapped)] autorelease]; 
     //[self.bookmarkButton addGestureRecognizer:gr]; 
    } 
} 

-(void)animateOutSplashImage:(UIImageView *)splashImg 
{ 
    [UIView animateWithDuration:1 animations:^{ 
     [splashImage setAlpha:0]; 

    }completion:^(BOOL finished){ 
     [splashImage removeFromSuperview]; 
     splashImage = nil; 
     //[self drawBookmarkButton]; 
    }]; 

} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [self drawBookmarkButton]; 
} 

をうまく動作します。これを理解しようとしている間に過ごしたが、何も動いていない。

ありがとうございます!

+0

bookmarkButtonTappedメソッドについて珍しいことは何ですか? –

+0

いいえ、ブレークポイントを設定しても呼び出されません。それはちょうどビューコントローラをnabコントローラにプッシュします。 – Marky

答えて

0

謝罪、それは(私といつものように)愚かな間違いだった!

self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; 
self.navigationController.navigationBar.translucent = YES; 

をし、それを忘れている必要があります:私は設定デリゲートで

。ナビゲーションバーを非表示に設定すると、ナビゲーションバーがボタンをブロックしていないことになります。

ありがとうございました!

0

あなたもheaderViewのためのUIViewのインスタンスを作成し、ビューにImageViewのとボタンを追加

[contentsHeaderImageView bringSubViewToFront:self.bookmarkButton]; 

を試してみました。

+0

ありがとう、私はそれを試して、それは動作しませんでした – Marky

+0

ああ!ボタンを50px下に移動すると機能します。私はそれが隠されたナプバーと関係があると思う。 – Marky

関連する問題