Method is not called

I associated the button with the following method:

- (IBAction)searchButton
{
    NSString *searchText = _searchField.text;
    NSLog(@"lol");
    [_search testSearch:searchText];
}

The last line calls the testSearch method in an object named search, defined as follows:

@property (strong, nonatomic) Search *search;

Inside a search, testSearch is defined as follows:

-(void)testSearch:(NSString *)testString
{
    NSLog(@"HELLO");
}

My end result when I click search is only "lol" (every time I click the button). It does NOT print "HELLO" as testSearch should do. I have included testSearch in Search.h, so it should be available ... why is this method not being called?

0
source share
2 answers

You should start by initializing your _searchivar instance Searchin the initializer you have assigned (or in viewDidLoador another "user who will use this method").

- init {
   if ((self = [super init])) {
       _search = [[Search alloc] init];
   }
   return self;
}

:

  • ; @property . .

  • , , , . , KVO (, , KVO... ).

  • , , , , , .

  • . , " ", .

  • . , X Y, .

+6

, , , . Obj-C , . Objective-C iVar. , , iVars, , iVar . getter iVar:

-(Search *)search
{
     if(!_search){
        _search = [[Search alloc]init];
     }
     return _search;
}

, iVar:

[search testSearch:searchText];
0

All Articles