swift UITableViewCell 中的單選控制樣式

來源:互聯網
上載者:User

標籤:

   我昨天在網上找了一晚上的資料,但是大多都是OC得文法,swift資料實在是太少了,使得我這個剛入門swift的彩筆好不吃力,後面一直各種翻閱資料,終於讓我找到了

 visibleCells 這個方法,直接貼代碼:

我的思路是這樣的:

1.首先取得所有儲存格並遍曆取消打勾的樣式。

2.設定當前選中儲存格的樣式。

 //擷取將要選擇的儲存格的路徑

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){

        //取消選中的樣式

        tableView.deselectRowAtIndexPath(indexPath, animated: true);

        //擷取當前選中的儲存格

        var cell:UITableViewCell!=tableView.cellForRowAtIndexPath(indexPath);

        //返回所有儲存格

        //遍曆取消所有儲存格樣式

        var arry=tableView.visibleCells();

        for(var  i=0;i<arry.count;i++){

            var cells:UITableViewCell=arry[i] as! UITableViewCell;

            cells.accessoryType=UITableViewCellAccessoryType.None

        }

        //設定選中的儲存格樣式

        cell.accessoryType=UITableViewCellAccessoryType.Checkmark;     

       

    }

運行如:

 

 

反正我覺得學swift學了快2個月了,並且還是一邊學一邊實戰寫項目,就個人覺得吧,這個思路邏輯太他媽重要了,看來這些軟知識要多多補一下了。

PS:有寫的不對的地方請多多噴我,千萬不要吝嗇你的文采,我是彩筆我自豪!

 

swift UITableViewCell 中的單選控制樣式

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.