Swift 在TableView上选择Rowatindexpath
不知道我做错了什么。我得到这个错误: 致命错误:在展开可选文件时意外发现nil 此行中的值Swift 在TableView上选择Rowatindexpath,swift,Swift,不知道我做错了什么。我得到这个错误: 致命错误:在展开可选文件时意外发现nil 此行中的值self.profileImage.image=UIImage(数据:数据) 在I选择rowatindexpath之后。我不想以发件人的身份发送任何内容,但当我尝试使用标识符执行搜索时,它似乎正在尝试获取该手机?为什么在我选择configureCell函数后它会再次调用它 视图控制器 FriendsTableViewCell 似乎profileImage是nil。接口生成器中的插座是否正确连接?是否已连接。
self.profileImage.image=UIImage(数据:数据)
在I选择rowatindexpath
之后。我不想以发件人的身份发送任何内容,但当我尝试使用标识符执行搜索时,它似乎正在尝试获取该手机?为什么在我选择configureCell函数后它会再次调用它
视图控制器
FriendsTableViewCell
似乎
profileImage
是nil
。接口生成器中的插座是否正确连接?是否已连接。它显示配置文件图像。请尝试在错误日志中键入下一个采购订单数据。查看它将返回的内容设置断点或插入打印行以检查profileImage
是否为nil
@iamalizade数据
显然不是nil
,UIImage(数据:)
将返回nil
,如果数据
无法识别为图像数据。结果是不会显示任何图像,但应用程序不会崩溃。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
victim = friends[indexPath.row] as Friend!
DataService.shared.setVictim(victim!)
print("It got here with friend: \(victim!)")
performSegueWithIdentifier("commentFromSegue", sender: nil)
}
class FriendTableViewCell: UITableViewCell {
@IBOutlet weak var friendName: UILabel!
@IBOutlet weak var profileImage: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
layer.cornerRadius = 5.0
}
func configureCell(friend: Friend) {
let url = NSURL(string: friend.profileImg)
if let data = NSData(contentsOfURL: url!) {
self.profileImage.image = UIImage(data: data)
// works if I comment out the above line. but does not show profile image
}
friendName.text = friend.friendName
}
}