工作的一個應用程序,並使用下面的代碼: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];
}
出於某種原因,第一次應用程序運行書籤按鈕將不會對水龍頭回應,但如果我把一個視圖控制器然後返回它的工作正常。花了一段時間試圖弄清楚這一點,沒有任何工作。
任何想法???
謝謝!
關於bookmarkButtonTapped方法的任何不尋常的事情? –
不,在它上面設置一個斷點,它不會被調用。它只是將視圖控制器推到nab控制器上。 – Marky