Understanding methods in objective-c

for example, we use this method in a table view

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 16;
}

I want to know that we do not call this method anywhere, but the application reads this value, what does it look like? we did not call such methods.

+3
source share
4 answers

Your object was set as a UITableView data source somewhere. Most likely, creating a connection in InterfaceBuilder, although this is easy to do in code by setting the dataSourceUITableView property :

- (void) setUpMyJunkMan
{
    myTableView.dataSource = self;
}

After you set your object as a data source, the table view will call the method as necessary to determine what it needs to do or how it needs to respond to events.

UITableViewDataSource (, InterfaceBuilder, , - , ).

UITableViewDataSource, , @optional. @required; .

. . , .

+11

, - , , .

- , .

, , , ( ) . TableViewController, , - .

+1

numberOfSectionsInTableView: .

numberOfSectionsInTableView: UITableViewDataSource. UITableView dataSource. UITableView UITableViewController, dataSource.

, numberOfSectionsInTableView: dataSource.

iPhone OS.

-1
source

This is part of the delegate interface.

At some point in your application (perhaps in your UIBuilder), you indicated that the object containing this method is actually a delegated object. This means that when you want to customize the behavior (in this case, a UITableView), you can without the UITableView extension, but with an explicit change in the delegate methods.

basically, the UITableView class will look something like this.

- (void) AMethodinUiTableView 
{

int colums =[self.delegate numberOfSectionsInTableView:self];
}

for more information, I would look at the delgate program and selector.

-4
source

Source: https://habr.com/ru/post/1715984/


All Articles