First of all I am very new in Objective C and iOS development.
Currently I am trying to use TableView
I have property
@property (strong, nonatomic) IBOutlet UITableView *tableView;//for table view
Now I seen something like this,
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
What is exact meaning of the code. What I am doing with tableView
here, and how name of property and name of message is same, ie tableView
.
In first line you are declaring property of an tableview which you create by storyboard.
The goal of the @property
directive is to make it easy to create and configure properties by automatically generating these accessor methods. It allows you to specify the behavior of a public property on a semantic level, and it takes care of the implementation details for you.
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
This is a tableview delegate method which define the no of row in a particular section in table view
data is your array name contain element which you want to show in tableview cell
[data count]
return the number of row in your table view
for more detail check
What I am doing with tableView here
tableView:numberOfRowsInSection:
is a method from the UITableViewDatasource Protocole to do simple, the object of type UITableView
will do something like it :
[self.delegate tableView:self numberOfRowsInSection:section]
and so, if you do tableView.datasource = self
in your viewController
, it's this object which will receive the message and so, need to answer to the tableview
.
and how name of property and name of message is same, ie tableView.
@property
is just an indication for the compiler to create accessors and iVar in your class, that why it seems to do many things at the same time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.