次のコードがあります。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImage * search = [UIImage imageNamed: @"search.png"];
UIImageView * s = [[UIImageView alloc] initWithImage: search];
s.frame = CGRectMake(15, 14, search.size.width, search.size.height);
UIImage * simg = [UIImage imageNamed: @"m_search_back.png"];
UIImage * img = [UIImage imageNamed: @"m_top.png"];
CGRect searchBarFrame = CGRectMake(0, 0, self.tableView.frame.size.width, 45.0);
self.searchBar = [[UISearchBar alloc] initWithFrame:searchBarFrame];
self.searchBar.backgroundImage = simg;
[self.searchBar setSearchFieldBackgroundImage: simg forState:UIControlStateNormal];
self.searchBar.delegate = self;
[self.searchBar addSubview: s];
UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];
// Change search bar text color
searchField.textColor = [UIColor colorWithRed: 178.0/255 green:178/255.0 blue:178/255.0 alpha:1.0];
searchField.font = [UIFont fontWithName: @"HelveticaNeue-Light" size: 16.0f];
// Change the search bar placeholder text color
[searchField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
[self.searchBar setPlaceholder:@"Search for investors, startups, founders, etc"];
UIImageView * top = [[UIImageView alloc] initWithImage: img];
top.frame = CGRectMake(0, self.searchBar.frame.size.height + 1, 800, img.size.height);
UILabel * topl = [[UILabel alloc] initWithFrame: CGRectMake(30, 10, 800, img.size.height - 30)];
topl.text = @"Connect with\nFounders and Investors";
topl.numberOfLines = 0;
topl.backgroundColor = [UIColor clearColor];
topl.textColor = [UIColor whiteColor];
topl.textAlignment = NSTextAlignmentCenter;
[topl setFont: [UIFont fontWithName: @"HelveticaNeue-Bold" size: 17.0f]];
[topl sizeToFit];
[top addSubview: topl];
UIImage * loginbtn = [UIImage imageNamed: @"loginbtn.png"];
UIImage * sep1 = [UIImage imageNamed: @"m_sep1.png"];
UIButton * login = [[UIButton alloc] initWithFrame: CGRectMake(30, 70, loginbtn.size.width, loginbtn.size.height)];
[login.titleLabel setFont: [UIFont fontWithName: @"HelveticaNeue-Medium" size: 16.0f] ];
[login setTitle:@"Login" forState: UIControlStateNormal];
[login addTarget: self action:@selector(loginUser:) forControlEvents:UIControlEventTouchUpInside];
[login setBackgroundImage: loginbtn forState: UIControlStateNormal];
[top addSubview: login];
UIImage * greenbtn = [UIImage imageNamed: @"greenbtn.png"];
UIButton * green = [[UIButton alloc] initWithFrame: CGRectMake(loginbtn.size.width + 50, 70, greenbtn.size.width, greenbtn.size.height)];
[green setTitle:@"Register" forState: UIControlStateNormal];
[green.titleLabel setFont: [UIFont fontWithName: @"HelveticaNeue-Medium" size: 16.0f] ];
[green setBackgroundImage: greenbtn forState: UIControlStateNormal];
[green addTarget:self action:@selector(registerUser:) forControlEvents:UIControlEventTouchUpInside];
[top addSubview: green];
UIImageView * sep2 = [[UIImageView alloc] initWithImage: sep1];
sep2.frame = CGRectMake(0, top.frame.origin.y + top.frame.size.height - 2, top.frame.size.width, 1);
UIImage * sep5img = [UIImage imageNamed: @"m_sep5.png"];
UIImageView * sep5 = [[UIImageView alloc] initWithImage: sep5img];
sep5.frame = CGRectMake(0, self.searchBar.frame.origin.y + self.searchBar.frame.size.height, self.searchBar.frame.size.width, sep5img.size.height);
UIView * toph = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 800, simg.size.height + top.frame.size.height + 2)];
[toph addSubview: self.searchBar];
[toph addSubview: sep5];
[toph addSubview: top];
[toph addSubview: sep2];
return toph;
}
残念ながら、UIButton の「ログイン」にアクションを追加しようとしましたが、機能しません。loginUser 関数が呼び出されていません。私に何ができる?UIButton のアクションを正しく設定していますか?
ありがとう。