The implementation of the idea is relatively simple, here only to record:
Directly on the code:
1, implement Didselectrowatindexpath method
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{ [[ Nsuserdefaults Standarduserdefaults]setvalue:[array ObjectAtIndex:indexPath.row] forkey:app_changevoice]; [_sexttableview Reloaddata]; [TableView Deselectrowatindexpath:indexpath animated:yes]; }
Implement the method inside the Cellforrowatindexpath
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *celltableidentifier =@"Celltableidentifier"; Hpublickcell*cell =[TableView Cellforrowatindexpath:indexpath]; if(Cell = =Nil) {Cell=[[Hpublickcell alloc] initwithstyle:uitableviewcellstylevalue1 reuseidentifier:celltableidentifier]; Cell.selectionstyle=Uitableviewcellselectionstylenone; } Cell.textsLabel.text=Array[indexpath.row]; Cell.selectionstyle=Uitableviewcellselectionstylegray; //Select storage for State if([[[[ nsuserdefaults Standarduserdefaults]valueforkey:app_changevoice] Isequaltostring:[array objectAtIndex: Indexpath.row]]) {Cell.accessorytype=Uitableviewcellaccessorycheckmark; } Else{Cell.accessorytype=Uitableviewcellaccessorynone; } returncell; }
The array in this is the data source arrays. As follows:
2, above this is the system's selected style, the following is a custom:
The code is as follows:
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{Shippingaddresscell*cell = [TableView dequeuereusablecellwithidentifier:@"Shippingaddresscell"]; if(!cell) {Cell= [[Shippingaddresscell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:@"Shippingaddresscell"]; } if(Self.lastindexpath = =Indexpath) {Cell.selectedImg.image= [UIImage imagenamed:@"clicked"]; }Else{cell.selectedImg.image= [UIImage imagenamed:@"Unclick"]; } returncell;}-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{//previously selected, deselectShippingaddresscell *celled =[TableView Cellforrowatindexpath:_lastindexpath]; Celled.selectedImg.image= [UIImage imagenamed:@"Unclick"]; //record the currently selected position index_lastindexpath =Indexpath; //Tick of the current selectionShippingaddresscell *cell =[TableView Cellforrowatindexpath:indexpath]; Cell.selectedImg.image= [UIImage imagenamed:@"clicked"];}
This can be achieved, as follows:
Multi-choice of free and perfect! Code can be pasted directly to use!
--tableview single-Choice implementation of iOS development