data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"];
    return cell;
}


These two methods are part of UITableView's data source protocol. The data source is the link between your data and the table view. Usually the view controller plays the role of data source and therefore implements these methods.


The table view needs to know how many rows of data it has and how it should display each of those rows. You should say to the table view: "The view controller is now your data source. You can ask it questions about the data anytime you feel like it."


Once it is hooked up to a data source, the table view sends a numberOfRowsInSection     message when it wants to know how many rows there are. And when the table view needs to display a particular row it sends the CellForRowAtIndexPath  message to ask the data source for a cell.

Don't be confused with cells and rows pp25

When we make numberOfRowsInSection  return the number 5, we tell the table view that there will be five rows. The table view then calls cellForRowAtIndexPath five times, once for each row.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值