是否可以在不重新加载单元格的情况下为自定义UITableViewCell中的UILabel设置值?
我尝试了许多排列:
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomTableViewCell1
cell.customLabel.text = "text goes here"
..我不明白为什么这不起作用。我在UITableViewCell中有一个UITextField,当我设置textField值时,我只想更新标签,但不重新加载整个单元格。有什么建议吗?
答案 0 :(得分:2)
如果要更新UIViews
,则需要将它们放在主线程中:
dispatch_async(dispatch_get_main_queue(),{
cell.customLabel.text = "text goes here"
})
答案 1 :(得分:2)
<table border="1px" width="90%" id="data">
<tr>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Order</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Sr No.</font><span></span></label></td>
<td width="580px" align="center"><label for=""><font color="#0099FF" size="3px">Description</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Unit</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Previous Qty.</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">This Bill Qty</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Total Quantity</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Rate</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Amount</font><span></span></label></td>
</tr>
<tr>
<td><input type="text" size="6" maxlength="6" maxlength="6" name="ord_' + currentItem + '" class="form-input-oth" onkeyup="return copy(this.val());"/></td>
<td><input type="text" size="6" maxlength="6" maxlength="6" name="srno_' + currentItem + '" class="form-input-oth"/></td>
<td><textarea name="descrip_' + currentItem + '" cols="70" class="form-input-textareasm"></textarea></td>
<td><input type="text" size="6" maxlength="9" maxlength="6" name="unit_' + currentItem + '" class="form-input-rate"/></td>
<td><input type="text" size="6" maxlength="9" maxlength="6" name="prevqty_' + currentItem + '" class="prevqty "/></td>
<td><input type="text" size="6" maxlength="9" maxlength="6" name="thisqty_' + currentItem + '" class="thisqty "/></td>
<td><input type="text" size="6" maxlength="9" maxlength="6" name="qty_' + currentItem + '" class="qty "/></td>
<td><input type="text" size="6" maxlength="9" maxlength="6" name="rate_' + currentItem + '" class="rate "/></td>
<td><input type="text" size="6" maxlength="9" maxlength="6" name="amt_' + currentItem + '" class="cal"/></td>
</tr>
<tr>
<td colspan="8"></td>
<td><input type="text" id="total"/></td>
</tr>