请帮我.
这是我的第一个屏幕
我添加了一个“文件”和两个“数字”
我删除了“文件”但第二部分没有上传.
代码:
#import "VIEwController.h"@interface VIEwController ()@end@implementation VIEwController@synthesize tblListe,btnCancel,btnEdit;- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; self.automaticallyAdjustsScrollVIEwInsets = NO; fileArr = [[NSMutableArray alloc] init]; NumberArr = [[NSMutableArray alloc] init];}-(NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section{ int a=0; if (section==0) { if(fileArr.count>0) a=fileArr.count; } else { if(NumberArr.count>0) a=NumberArr.count; } return a;}-(NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw{ return 2;}-(CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForheaderInSection:(NSInteger)section{ return 37.0;}-(UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UItableVIEwCell *hucre = [[UItableVIEwCell alloc] init]; if(indexPath.section==0){ hucre.textLabel.text=[fileArr objectAtIndex:indexPath.row]; }else{ hucre.textLabel.text=[NumberArr objectAtIndex:indexPath.row]; } hucre.accessoryType = UItableVIEwCellAccessorydisclosureIndicator; return hucre;}-(UIVIEw *)tableVIEw:(UItableVIEw *)tableVIEw vIEwForheaderInSection:(NSInteger)section{ UIVIEw *AnaVIEw=[[UIVIEw alloc]initWithFrame:CGRectMake(0,self.vIEw.frame.size.wIDth,0)]; UIVIEw *AsilVIEw=[[UIVIEw alloc]initWithFrame:CGRectMake(5,35)]; CGRect labelFrame = CGRectMake(5,self.vIEw.frame.size.wIDth/3,35); UILabel *myLabel = [[UILabel alloc] initWithFrame:labelFrame]; int say=0; if(section==0){ myLabel.text = @"files"; say=fileArr.count; }else{ myLabel.text = @"Numbers"; say=NumberArr.count; } myLabel.Font = [UIFont boldSystemFontOfSize:14.0f]; myLabel.textAlignment = NSTextAlignmentCenter; myLabel.textcolor = [UIcolor whitecolor]; myLabel.backgroundcolor = [self colorWithHexString:@"ce1b27"]; UIVIEw *lineVIEw=[[UIVIEw alloc]initWithFrame:CGRectMake(5,AsilVIEw.frame.size.height,self.vIEw.frame.size.wIDth-5,2)]; lineVIEw.backgroundcolor = [self colorWithHexString:@"ce1b27"]; [AnaVIEw addSubvIEw:AsilVIEw]; [AnaVIEw addSubvIEw:myLabel]; [AnaVIEw addSubvIEw:lineVIEw]; if (say>0) { return AnaVIEw; }else{ return nil; }}-(Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw TitleForheaderInSection:(NSInteger)section{ Nsstring *x; if (section==0) { if(fileArr.count>0) x=@"files"; else x=nil; } else { if (NumberArr.count>0) x=@"Numbers"; else x=nil; } return x;}-(Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw TitleForDeleteConfirmationbuttonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"Delete";}-(voID)tableVIEw:(UItableVIEw *)tableVIEw commitEditingStyle:(UItableVIEwCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if(editingStyle == UItableVIEwCellEditingStyleDelete){ if (indexPath.section==0) { [fileArr removeObjectAtIndex:indexPath.row]; }else{ [NumberArr removeObjectAtIndex:indexPath.row]; } } [self SatirIslem:0]; //NSLog(@"%@",fileArr); [tblListe reloadData];}-(BOol)tableVIEw:(UItableVIEw *)tableVIEw canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}- (IBAction)DuZenle:(ID)sender { [tblListe setEditing:YES animated:YES]; btnCancel.enabled = YES;}- (IBAction)Iptal:(ID)sender { [tblListe setEditing:NO animated:YES]; btnCancel.enabled = NO;}- (IBAction)DosyaEkle:(ID)sender { [fileArr addobject:@"This is a file"]; [self SatirIslem:1];}- (IBAction)NumaraEkle:(ID)sender { [NumberArr addobject:@"This is a Number"]; [self SatirIslem:1];}-(voID)SatirIslem:(NSInteger) islem{ CGfloat x=0,y=0,w=0,h=0; if (islem==1) { // satır Ekle x=tblListe.frame.origin.x; y=tblListe.frame.origin.y; w=tblListe.frame.size.wIDth; h=tblListe.frame.size.height; if(fileArr.count==1 || NumberArr.count==1){ h+=35+44; // 35 header için 44 satır için }else{ h+=44; } } if (islem==0) { x=tblListe.frame.origin.x; y=tblListe.frame.origin.y; w=tblListe.frame.size.wIDth; h=tblListe.contentSize.height; if(fileArr.count==0 && NumberArr.count==0){ h=1; }else if(fileArr.count==0 || NumberArr.count==0) { h-=44+35;// 35 header için 44 satır için }else{ h-=44; } } tblListe.frame=CGRectMake(x,y,w,h); [tblListe reloadData];}-(UIcolor*)colorWithHexString:(Nsstring*)hex{ Nsstring *cString = [[hex stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; if ([cString length] < 6) return [UIcolor graycolor]; if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2]; if ([cString length] != 6) return [UIcolor graycolor]; NSRange range; range.location = 0; range.length = 2; Nsstring *rString = [cString substringWithRange:range]; range.location = 2; Nsstring *gString = [cString substringWithRange:range]; range.location = 4; Nsstring *bString = [cString substringWithRange:range]; unsigned int r,g,b; [[NSScanner scannerWithString:rString] scanHexInt:&r]; [[NSScanner scannerWithString:gString] scanHexInt:&g]; [[NSScanner scannerWithString:bString] scanHexInt:&b]; return [UIcolor colorWithRed:((float) r / 255.0f)green:((float) g / 255.0f) blue:((float) b / 255.0f)Alpha:1.0f];}@end解决方法 您可以通过返回高度的不同值来解决此问题.
-(CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForheaderInSection:(NSInteger)section{ if (section==0) { if(fileArr.count==0) return 0; } else { if(NumberArr.count==0) return 0; } return 37.0;}总结
以上是内存溢出为你收集整理的ios – 如何删除UITableView节头删除后创建的空间?全部内容,希望文章能够帮你解决ios – 如何删除UITableView节头删除后创建的空间?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)