我正在使用swift for iPhone创建一个Todo应用程序。我希望tableview在tableview中显示任务的名称和时间。 Textlabel显示任务的正确名称,但detailTextLabel只显示详细信息,而不显示时间。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell") as UITableViewCell!
let task = tasks[indexPath.row]
if task.done {
cell?.textLabel!.text = "‼️\(task.name!)"
task.time = cell!.detailTextLabel!.text
} else {
cell?.textLabel!.text = "\(task.name!)"
task.time = cell!.detailTextLabel!.text
}
return cell!
}
答案 0 :(得分:0)
您对detailTextLabel的分配是向后的。
function renderMediaUploader() {
'use strict';
var file_frame, image_data;
/**
* If an instance of file_frame already exists, then we can open it
* rather than creating a new instance.
*/
if ( undefined !== file_frame ) {
file_frame.open();
return;
}
/**
* If we're this far, then an instance does not exist, so we need to
* create our own.
*
* Here, use the wp.media library to define the settings of the Media
* Uploader. We're opting to use the 'post' frame which is a template
* defined in WordPress core and are initializing the file frame
* with the 'insert' state.
*
* We're also not allowing the user to select more than one image.
*/
file_frame = wp.media.frames.file_frame = wp.media({
title: 'Select or Upload Media Of Your Chosen Persuasion',
button: {
text: 'Use this media'
},
multiple: true
});
//add items from thickbox to table
file_frame.on( 'select', function() {
var attachment = file_frame.state().get('selection').toJSON();
jQuery.each(attachment, function(i, val){
jQuery('table').show();
jQuery('table tbody').append('<tr class="table_row"><td class="col-sm-2"><img class="img-responsive" src="'+val.url+'"></td><td class="col-sm-8"><input style=" display: block;" type="text" name="entry[url][]" value="'+ val.url +'"></td></tr>');
});
});
// Now display the actual file_frame
file_frame.open();
}
(function( $ ) {
'use strict';
$(function() {
$( '#set-footer-thumbnail' ).on( 'click', function( evt ) {
// Stop the anchor's default behavior
evt.preventDefault();
// Display the media uploader
renderMediaUploader();
});
});
})( jQuery );
答案 1 :(得分:0)
您实际上从未将细节标签文本设置为任何内容。您需要使用以下内容进行设置:
cell?.detailTextLabel!.text = task.time.longStyleDateString
以及日期延期:
extension Date {
var longStyleDateString: String {
let formatter = DateFormatter()
formatter.dateStyle = .long
return formatter.string(from: self)
}
}