ios tableview单选

 //设置默认选中
<code class="hljs objectivec has-numbering">    <span class="hljs-built_in">NSIndexPath</span>*defaultIndexPath = [<span class="hljs-built_in">NSIndexPath</span> indexPathForRow:<span class="hljs-number">0</span> inSection:<span class="hljs-number">0</span>];
    [<span class="hljs-keyword">self</span> tableView:<span class="hljs-keyword">self</span><span class="hljs-variable">.tableView</span> didSelectRowAtIndexPath:defaultIndexPath];</code>
<code class="hljs objectivec has-numbering"></code> 
<code class="hljs objectivec has-numbering">- (<span class="hljs-keyword">void</span>)tableView:(<span class="hljs-built_in">UITableView</span> *)tableView didSelectRowAtIndexPath:(<span class="hljs-built_in">NSIndexPath</span> *)indexPath{         <span class="hljs-comment">//当前cell row  </span>         <span class="hljs-built_in">NSInteger</span> newRow = [indexPath row];         <span class="hljs-comment">//记录上一次cell row</span>         <span class="hljs-built_in">NSInteger</span> oldRow = (<span class="hljs-keyword">self</span><span class="hljs-variable">.lastIndexPath</span> != <span class="hljs-literal">nil</span>) ? [<span class="hljs-keyword">self</span><span class="hljs-variable">.lastIndexPath</span> row] : -<span class="hljs-number">1</span>;        <span class="hljs-keyword">if</span> (newRow != oldRow)          {               <span class="hljs-comment">//选中cell</span>               CustomTableViewCell *newcell =  [tableView cellForRowAtIndexPath:indexPath];               newcell<span class="hljs-variable">.selectImage</span><span class="hljs-variable">.hidden</span> = <span class="hljs-literal">NO</span>;               <span class="hljs-comment">//取消上一次选中cell</span>              CustomTableViewCell *oldCell = [tableView cellForRowAtIndexPath:<span class="hljs-keyword">self</span><span class="hljs-variable">.lastIndexPath</span>];               oldCell<span class="hljs-variable">.selectImage</span><span class="hljs-variable">.hidden</span> = <span class="hljs-literal">YES</span>;          }            <span class="hljs-keyword">self</span><span class="hljs-variable">.lastIndexPath</span> = indexPath;}</code>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值