Ios 用内容填充表视图
我是iphone应用程序开发新手 我目前有一个表视图,但想用我自己的新闻故事填充它。你知道我该怎么做吗 目前我有以下几点:Ios 用内容填充表视图,ios,objective-c,iphone,swift,tableview,Ios,Objective C,Iphone,Swift,Tableview,我是iphone应用程序开发新手 我目前有一个表视图,但想用我自己的新闻故事填充它。你知道我该怎么做吗 目前我有以下几点: override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", for
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! NewsTableViewCell
// Configure the cell...
if indexPath.row == 0 {
cell.postImageView.image = UIImage(named: "premier-league")
cell.postTitleLabel.text = "Join our league"
cell.authorLabel.text = "Paul"
cell.authorImageView.image = UIImage(named: "author")
} else if indexPath.row == 1 {
cell.postImageView.image = UIImage(named: "example2")
cell.postTitleLabel.text = "Fixtures for the coming season"
cell.authorLabel.text = "Paul"
cell.authorImageView.image = UIImage(named: "author")
} else {
cell.postImageView.image = UIImage(named: "example3")
cell.postTitleLabel.text = "New App for the new season"
cell.authorLabel.text = "Paul"
cell.authorImageView.image = UIImage(named: "author")
}
return cell
}
好的,那么您需要了解的是上面显示的方法
cellforrowatinedexpath
,是一个重复调用的方法,它填充了tableView的单元格,这就是它的全部内容
因此,如果您有以下实现:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! NewsTableViewCell
// Configure the cell...
cell.textLabel.text = "Hello"
return cell
}
然后每个单元格的文本标签将填充“hello”一词
在此基础上展开,只需使用要在tableView中显示的数据(即字符串名称、日期、一些其他数据的数组)填充数组(或其他对象),然后在cellforrowatinexpath
中使用该数据设置单元格的属性(textLabel或其他)
最好的一位是,每个indexPath.row都是每个数组位置的完美模拟。因此,数组和表视图可以很好地结合在一起。好的,那么您需要了解的是上面显示的方法cellforrowatinexpath
,是一种重复调用的方法,它填充表视图的单元格,这就是它的全部内容
因此,如果您有以下实现:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! NewsTableViewCell
// Configure the cell...
cell.textLabel.text = "Hello"
return cell
}
然后每个单元格的文本标签将填充“hello”一词
在此基础上展开,只需使用要在tableView中显示的数据(即字符串名称、日期、一些其他数据的数组)填充数组(或其他对象),然后在cellforrowatinexpath
中使用该数据设置单元格的属性(textLabel或其他)
最好的一位是,每个indexPath.row都是每个数组位置的完美模拟。因此数组和表视图可以很好地结合在一起。cellforrowatinexpath
不是递归调用的。也许你的意思是“反复呼叫?”@ndmeiri是的!对不起:)没问题!希望以后的读者在仔细阅读您的完整答案时不会产生任何困惑:)cellforrowatinexpath
不是递归调用的。也许你的意思是“反复呼叫?”@ndmeiri是的!对不起:)没问题!我只是希望未来的读者能够仔细阅读你的完整答案,避免产生任何困惑:)对不起,我解释得不太清楚。我想用wordpress提供的rss源填充表格,以将我的图像包含在上述格式中。对不起,我解释得不太清楚。我想用wordpress提供的rss提要填充表格,以包含上述格式的图像。