我在自定义UITextView
中有UITableViewCell
。 textview委托在tableviewcell自定义类中分配。 Textview滚动已禁用。文本加载到每个文本视图中并且是多行的。但是文本总是被剪切,因为单元格高度没有变化。
我在tableview控制器的viewDidLoad
中有以下内容:
tableView.estimatedRowHeight = 56.0
tableView.rowHeight = UITableViewAutomaticDimension
知道为什么这不起作用吗?
答案 0 :(得分:2)
完美地尝试我的回答。
FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
if (auth.currentUser?.isEmailVerified)!{
let mainStoryboard: UIStoryboard = UIStoryboard(name:"Main",bundle:nil)
let NewPostViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "NewPostViewController")
//Send the user to the LoginViewController
self.present(NewPostViewController, animated: true, completion: nil)
}else{
let alertVC = UIAlertController(title: "Error", message: "Sorry. Your email address has not yet been verified. Do you want us to send another verification email to \(self.currentUser.generalDetails.email).", preferredStyle: .alert)
let alertActionOkay = UIAlertAction(title: "Okay", style: .default) {
(_) in
FIRAuth.auth()?.currentUser?.sendEmailVerification(completion: nil)
}
let alertActionCancel = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alertVC.addAction(alertActionOkay)
alertVC.addAction(alertActionCancel)
self.present(alertVC, animated: true, completion: nil)
}
})
将此代码放入viewDidLoad()
var record : NSArray = NSArray()
var hight: CGFloat = 0.0
在Swift 3.0中
record = ["I have a UITextView in a custom UITableViewCell. The textview delegate is assigned in the tableviewcell custom class." ,"Textview scrolling is disabled. Text loads into each textview and is multiline. But the text is always clipped because the cell height doesn't change.","I have the following in viewDidLoad of the tableview controller:"," have a UITextView in a custom UITableViewCell. The textview delegate is assigned in the tableviewcell custom class.","Textview scrolling is disabled. Text loads into each textview and is multiline. But the text is always clipped because the cell height doesn't change.","I have the following in viewDidLoad of the tableview controller:","i just give you one link at put place i use label and you can now use your textview and give same constrain that i give in that link and try it so your problem will be solve","I have the following in viewDidLoad of the tableview controller:"];
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return record.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Textviewcell", forIndexPath: indexPath)
let textview: UITextView = (cell.viewWithTag(5) as! UITextView)
textview.text = record.objectAtIndex(indexPath.row) as? String
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
// 7.1>
hight = self.findHeightForText(self.record.objectAtIndex(indexPath.row) as! String, havingWidth: self.view.frame.size.width - 10, andFont: UIFont.systemFontOfSize(14.0)).height
return 44 + hight
}
func findHeightForText(text: String, havingWidth widthValue: CGFloat, andFont font: UIFont) -> CGSize {
var size = CGSizeZero
if text.isEmpty == false {
let frame = text.boundingRectWithSize(CGSizeMake(widthValue, CGFloat.max), options: .UsesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
size = CGSizeMake(frame.size.width, ceil(frame.size.height))
}
return size
}
以下是一些屏幕截图。故事板
使用UITextView的运行时表视图
答案 1 :(得分:-2)
您应该使用委托方法
$folderA = "c:\tmp"
$folderB = "c:\tmp2"
$hashA = "c:\hashofA.txt"
$hashB = "c:\hashofB.txt"
Get-ChildItem $folderA -Recurse -File | Get-FileHash -Algorithm MD5 | Select -ExpandProperty Hash >> $hashA
Get-ChildItem $folderA -Recurse | foreach{ Copy-Item $_.FullName $folderB}
Get-ChildItem $folderB -Recurse -File | Get-FileHash -Algorithm MD5 | Select -ExpandProperty Hash >> $hashB
$a = Get-Content $hashA
$b = Get-Content $hashB
if(Compare-Object $a $b)
{"Files are different"}
else{"Files are same"}
设置行的高度。然后,在该方法中,通过计算将占据空间的textview的高度返回单元格应该的高度。您应该使用以下功能:
void Main()
{
DataTable workTable = new DataTable("Order");
DataColumn workCol = workTable.Columns.Add("BookingDate", typeof(String));
workTable.Columns.Add("Status", typeof(String));
workTable.Columns.Add("BookingNumber", typeof(int));
workTable.Rows.Add("2016/10/14","1",3);
workTable.Rows.Add("2016/10/14","1",1);
workTable.Rows.Add("2016/10/14","1",5);
workTable.Rows.Add("2016/10/13","1",7);
workTable.Rows.Add("2016/10/13","1",4);
workTable.Rows.Add("2016/10/12","1",8);
workTable.Rows.Add("2016/10/12","1",3);
workTable.Rows.Add("2016/10/12","1",6);
workTable.Rows.Add("2016/10/12","1",2);
workTable.AsEnumerable().GroupBy(x=>x.Field<string>("BookingDate")).Dump();
}
这将确定文本视图在单元格中占据的矩形。返回的高度等于文本视图的高度,因此如果您希望单元格高于文本框,请添加该填充。
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
希望这有帮助!