работает в приложении и использует следующий код:
- (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];
}
По какой-то причине при первом запуске приложения кнопка закладки не реагирует на нажатия, но если я нажимаю контроллер представления, то возвращаюсь, он работает нормально. Потратил некоторое время, пытаясь понять это, и ничего не работает.
Есть идеи ???
Спасибо!