我有一个tableview单元的子类。
class profileTableViewCell: UITableViewCell {
@IBOutlet weak var tableviewUsernameLabel: UILabel!
@IBOutlet weak var tableviewMessageLabel: UILabel!
@IBOutlet weak var tableviewTimeStamp: UILabel!
}
我需要在viewcontroller中访问这些标签。我怎么能这样做呢。我对编程很陌生。
- 我在下面的标签上显得“未解决的标识符”。如何访问这些标签?
- 也尝试将所有标签的inf.tableViewUsername.text(cell。)放在前面仍无效。
class UserProfile: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = profileTableView.dequeueReusableCell(withIdentifier: "profileCell")
//Set username label to display username
let usernameLabel = cell?.viewWithTag(1) as! UILabel
tableviewUsernameLabel.text = profileDataArray[indexPath.row].username
//Set message label to display message
let messageLabel = cell?.viewWithTag(2) as! UILabel
tableviewMessageLabel.text = profileDataArray[indexPath.row].message
tableviewMessageLabel.numberOfLines = 0
//Set timeStampLabel to current time AGO
let timeStampLabel = cell?.viewWithTag(4) as! UILabel
tableviewTimeStamp.text = profileDataArray[indexPath.row].timeStamp
tableviewTimeStamp.numberOfLines = 0
return cell!
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return profileDataArray.count // your number of cell here
}
}
答案 0 :(得分:3)
您必须dequeueReusableCell(withIdentifier:)
profileTableViewCell
返回let cell = profileTableView.dequeueReusableCell(withIdentifier: "profileCell") as! profileTableViewCell
cell.tableviewUsernameLabel.text = ...
cell.tableviewMessageLabel.text = ...
cell.tableviewTimeStamp.text = ...
return cell
的单元格。{/ p>
@action.bound uploadFile() {
let form = new FormData();
form.append("file", this.file);
$.ajax({
url: AppConstants.APIEndpoints.USERLOCATIONS + '/1/photos/1/upload',
headers: { "Authorization": localStorage.getItem('authToken') },
data: form,
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
alert(this.data.name + " uploaded successfully!");
}
});
}