這個還是最開始進入到iOS行業(yè)中的代碼之前寫的完全不能看,只是簡單記載一下。偶爾翻到,更新一下吧。
之前可能寫起來感覺好麻煩,現(xiàn)在回想一下感覺寫的好弱智。。
但是畢竟是當(dāng)初第一次項目中總結(jié)出來的代碼,又不舍得刪,留個紀(jì)念吧。。。
功能的話就只是一個簡單的利用鍵值來取Cell高度進行隱藏或者顯示的功能
定義
@interface ViewController(){
NSMutableArray* list;
NSMutableDictionary* dic1;
NSMutableDictionary* dic2;
NSMutableDictionary* sallDic;
}
@end
之前項目需求做多語言版本所以就加上了NSLocalizedString
初始化值
- (void)viewDidLoad
{
[superviewDidLoad];
dic1= [[NSMutableDictionary alloc]init];
dic2= [[NSMutableDictionary alloc]init];
[dic1 setObject:NSLocalizedString(@"cent_cheliangbaoyang",@"車輛保養(yǎng)")forKey:@"name"];
[dic1 setObject:NSLocalizedString(@"cent_baoyangriqi",@"距保養(yǎng)過期里程:")forKey:@"one"];
[dic1 setObject:NSLocalizedString(@"cent_weiquandianhua",@"維修電話:")forKey:@"two"];
[dic2 setObject:NSLocalizedString(@"cent_baoxianzixun",@"保險咨詢")forKey:@"name"];
[dic2 setObject:NSLocalizedString(@"cent_baoxiuriqi",@"車輛保修期剩余時間:已超過0")forKey:@"one"];
[dic2 setObject:NSLocalizedString(@"cent_nianshengriqi",@"車輛年審期剩余時間:已超過0")forKey:@"two"];
list= [[NSMutableArrayalloc]init];
[list addObject:dic1];
[list addObject:dic2];
alldic= [[NSMutableDictionaryalloc]init];
}
cell個數(shù)
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return list.count;
}
生成Cell
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
*****添加Cell
//在自定義Cell里面添加一個顯示和隱藏的方法。
//當(dāng)初有點ZZ 沒有把這里面的方法貼出來
return cell;
}
根據(jù)保存的值進行取高度
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
NSString* name = [[list objectAtIndex:indexPath.row]objectForKey:@"name"];
return[[[lsallDic objectForKey:name]objectForKey:@"KEY"]isEqualToString:@"YES"]?100:50;
}
將allDic里面的值做變化,將@“key”的值進行改變,刷新當(dāng)前行
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSString* name = [[list objectAtIndex:indexPath.row]objectForKey:@"name"];
if([allDic objectForKey:name]==nil) {
NSMutableDictionary*seldic = [[NSMutableDictionaryalloc]init];
[seldic setObject:@"1"forKey:@"KEY"];
[seldic setObject:@"NO"forKey:name];
[alldic setObject:seldicforKey:name];
}
if([[[alldic objectForKey:name] objectForKey:@"KEY"] isEqualToString:@"YES"]) {
[[alldic objectForKey:name] setObject:@"NO"forKey:@"KEY"];
}else{
[[listisalldicobjectForKey:name]setObject:@"YES"forKey:@"KEY"];
}
[tableView reloadRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}