我使用以下方法创建一个单元格并在其中填充数据(改编自推文应用程序示例) 现在我想添加一个显示所选事件日期的新标签和一个将执行另一个操作的按钮。这里有2种方法:
def self.cellForEvent(event, inTableView:tableView)
cell = tableView.dequeueReusableCellWithIdentifier(EventCell::CellId) || EventCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:CellId)
cell.fillWithEvent(event, inTableView:tableView)
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton
cell
end
将数据填充到单元格中
def fillWithEvent(event, inTableView:tableView)
self.textLabel.text = event.name
puts event.image
unless event.image
self.imageView.image = nil
Dispatch::Queue.concurrent.async do
event_image_data = NSData.alloc.initWithContentsOfURL(NSURL.URLWithString(event.image_url))
if event_image_data
event.image = UIImage.alloc.initWithData(event_image_data)
Dispatch::Queue.main.sync do
self.imageView.image = event.image
tableView.delegate.reloadRowForEvent(event)
end
end
end
else
self.imageView.image = event.image
end
end