rihekopo
rihekopo

Reputation: 3350

Show UITableView after UIButton was tapped

I have a UITableView that i would like to hide until the user taps the button searchButtonTapped. (I'm also using this button as an IBAction.)

Originally i'm hiding the table view as you see in the viewDidLoad, and i wanna show it after the button was tapped, but it does not shown up after i tap the search button. Do i missed something? For me, it seems it should be work properly, after the button was tapped i refresh the table view.

my .h file

@property (weak, nonatomic) IBOutlet UIButton *searchButtonTapped;
- (IBAction)searchButton:(id)sender;

.m file

- (void)viewDidLoad
{
    [super viewDidLoad];

      self.tableView.hidden = YES;
}


- (void)buttonTapped:(id)sender {
    if (sender == self.searchButtonTapped) {
     self.tableView.hidden = NO;
      [self.tableView reloadData];
    }
}



- (IBAction)searchButton:(id)sender {

      [self searchSetup];
}

Upvotes: 0

Views: 56

Answers (2)

DaSilva
DaSilva

Reputation: 1358

you have declared only one IBAction, which is for the method searchButton.

This method call the searchSetup´s method. What is the purpose of it?

- (IBAction)searchButton:(id)sender {

      [self searchSetup];
}

So you must have another IBAction for buttonTapped method witch is currently a "void" method and not a IBAction. Or you make that connection from the storyBoard, or you must declare it programaticly like:

[self.searchButtonTapped addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]

Upvotes: 0

Duncan C
Duncan C

Reputation: 131503

It's impossible to tell from the little bit of code that you posted. Add NSLog statements in your buttonTapped method that show entering the method, entering the if statement, the value of searchButtonTapped, and the value of self.tableView.

Then you can tell if the method is getting called, if the if statement is evaluating as true, and if the table view is non-nil. One of those things is likely to be the cause of your problem.

I'm guessing that the if statement is wrong. what type is the property self.searchButtonTapped? Post the code that declares that property.

Based on the name I would guess that searchButtonTapped is a boolean?

Upvotes: 1

Related Questions