ios 项目总结二2

1 还是scrollview的使用,判断向左向后滑动的判断

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    newx=scrollView.contentOffset.x;
        if (xiaotu_array.count*650>newx) {
            if (newx != oldIx ) {
                //Left-YES,Right-NO
                if (newx > oldIx) {
                    huaTag++;
                    NSLog(@"右滑 ===%d",huaTag);
                }else if(newx < oldIx){
                    
                    huaTag--;
                    NSLog(@"左滑-- ===%d",huaTag);
                }
  oldIx = newx;
            }
        }    
}

当时判断左右滑动是有个方法,响应的Hugtag判断了,但是oldIx的位置总是滑动初始化显示的是上次的的位置,所以导致判断总是不正确,所以再点击按钮的时候重绘oldIx的位置为oldIx=0;

2 pagecontrol和UIscrollvew的结合实现,

pagecontrol = [[UIPageControl alloc]initWithFrame:CGRectMake(280, 680, 50, 23)];
    pagecontrol.numberOfPages = xiaotu_array.count;
    pagecontrol.currentPage = 0;
    pagecontrol.pageIndicatorTintColor = [UIColor blackColor];
    pagecontrol.currentPageIndicatorTintColor=[UIColor grayColor];
    [viewRight addSubview:pagecontrol];
- (void)scrollViewDidScroll:(UIScrollView *)scrollview
{
  根据scrollview的滑动判断page的位置
    if (scrollview==Bigscroll) {
        [seachView removeFromSuperview];
        isShowSearch=YES;
        int page = scrollview.contentOffset.x / 650;
        pagecontrol.currentPage = page;
        if (page < xiaotu_array.count) {
            [pagecontrol setHidden:NO];
            pagecontrol.currentPage=page;
            [pagecontrol setNumberOfPages:xiaotu_array.count];

        }else if(page >= xiaotu_array.count && page < streetImages.count+xiaotu_array.count)
        {
            [pagecontrol setHidden:NO];
            pagecontrol.currentPage=page-xiaotu_array.count;
            [pagecontrol setNumberOfPages:streetImages.count];
        }else
        {
            pagecontrol.hidden = YES;
        }

  
        
        if (scrollview.contentOffset.x/650 < xiaotu_array.count && scrollview.contentOffset.x/650 >= 0) {
            [mtt setImage:[UIImage imageNamed:@"dj-mtt.png"] forState:UIControlStateNormal];

            [biaoshi_line setFrame:CGRectMake(60, 36, 73, 5)];
        }
        if (scrollview.contentOffset.x/650 >= xiaotu_array.count && scrollview.contentOffset.x/650 < xiaotu_array.count+streetImages.count) {
            [jiePai setImage:[UIImage imageNamed:@"dj-jpt.png"] forState:UIControlStateNormal];
            [biaoshi_line setFrame:CGRectMake(193, 36, 73, 5)];
        }
        if (scrollview.contentOffset.x/650 == xiaotu_array.count+streetImages.count) {
            [dpt setImage:[UIImage imageNamed:@"dj-sjstj.png"] forState:UIControlStateNormal];

            [biaoshi_line setFrame:CGRectMake(345, 36, 73, 5)];
        }
        if (scrollview.contentOffset.x/650==xiaotu_array.count+streetImages.count+1) {
            [kccx setImage:[UIImage imageNamed:@"dj-kccx.png"] forState:UIControlStateNormal];
            if (isDrag==YES) {
                [self performSelector:@selector(loadKuCunData) withObject:nil afterDelay:0];
                isDrag=NO;
            }
            

        }

    }
    

}

 3 九宫格的实现 ,可以实现删除的实现,在scrollview添加的button实现

//初始化scrollview 
 [scroll removeFromSuperview];
    scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(90, 100, 1024-180, 768-170)];
    scroll.backgroundColor=[UIColor whiteColor];
    scroll.delegate=self;
    [self.view addSubview:scroll];
    isShowBtn=NO;
    [self performSelector:@selector(initBtn) withObject:self afterDelay:0];
//初始化九宫格button
-(void)initBtn{ int width = scroll.frame.size.width/4; for (int i=0; i<allArrys.count; i++) { t=i/4; int d=fmod(i, 4); UIView *nView = [[UIView alloc] initWithFrame:CGRectMake(width * d + 5+d*10, HIGHT * t +5+t*50, WIDTH, HIGHT)]; // NSLog(@"---%@",NSStringFromCGRect(nView.frame)); nView.backgroundColor=[UIColor whiteColor]; nView.tag=1000+i; UIImageView *BgImage=[[UIImageView alloc]init]; BgImage.frame=CGRectMake(0, 0, 145, 187); BgImage.backgroundColor=[UIColor clearColor]; BgImage.image=[UIImage imageNamed:@"bj.png"]; [nView addSubview:BgImage]; nView.backgroundColor=[UIColor whiteColor]; UIButton *appBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [appBtn setFrame:CGRectMake(2, 2, 141, 183)]; [appBtn addTarget:self action:@selector(goNext:) forControlEvents:UIControlEventTouchUpInside];//默认是走下一页 appBtn.tag = i; [nView addSubview:appBtn]; NSString *aaa=[[dicInfo objectForKey:[allArrys objectAtIndex:i]] objectForKey:@"danpin"]; // NSString *bbb=[NSString stringWithFormat:@"%@",aaa]; NSString *ss=[NSString stringWithFormat:@"Documents/styleSmall/x%@",aaa]; NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",ss]]; NSString *fileName=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSString *imageNames=[fileName stringByReplacingOccurrencesOfString:@"-" withString:@"1"]; [appBtn setImage:[UIImage imageWithData:[DataPist stringToByte:imageNames]] forState:UIControlStateNormal]; NSLog(@"---%@",dicInfo); UILabel *label1=[[UILabel alloc]init]; label1.frame=CGRectMake(0,187, 200, 20); label1.text=[[dicInfo objectForKey:[allArrys objectAtIndex:i]]objectForKey:@"huoHao"]; label1.textColor=[UIColor grayColor]; label1.font=[UIFont systemFontOfSize:12]; [nView addSubview:label1]; UILabel *label2=[[UILabel alloc]init]; label2.frame=CGRectMake(0,187+20, 150, 20); label2.text=[[dicInfo objectForKey:[allArrys objectAtIndex:i]]objectForKey:@"chanPinName"]; label2.textColor=[UIColor grayColor]; label2.font=[UIFont systemFontOfSize:12]; [nView addSubview:label2]; UILabel *label3=[[UILabel alloc]init]; label3.frame=CGRectMake(0,187+40, 30, 20); label3.text=@"RMB"; label3.textColor=[UIColor grayColor]; label3.font=[UIFont systemFontOfSize:12]; [nView addSubview:label3]; UILabel *label4=[[UILabel alloc]init]; label4.frame=CGRectMake(40,187+40, 100, 20); NSString *price=[[dicInfo objectForKey:[allArrys objectAtIndex:i]]objectForKey:@"money"]; // label4.text=[price substringToIndex:price.length-5]; label4.text=price; label4.textColor=[UIColor grayColor]; label4.font=[UIFont systemFontOfSize:12]; [nView addSubview:label4]; UIImageView *tagImgView = [[UIImageView alloc] initWithFrame:CGRectMake(145-31, 1, 30, 30)]; [tagImgView setImage:[UIImage imageNamed:@"sc.png"]]; [tagImgView setHidden:YES]; [nView addSubview:tagImgView]; [scroll addSubview:nView]; // nView.userInteractionEnabled = YES; [scroll setContentSize:CGSizeMake( 1024-180,(t+1)*280+50)]; // NSLog(@"-=t=%d==--%@",t,NSStringFromCGRect(scroll.frame)); } UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressGestureRecognizer:)]; [scroll addGestureRecognizer:lpgr]; UITapGestureRecognizer *oneFinger=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneFinger:)]; oneFinger.numberOfTapsRequired = 1; oneFinger.delegate=self; [scroll addGestureRecognizer:oneFinger]; // [self performSelector:@selector(jisuan) withObject:nil afterDelay:1]; }

添加方法

//判断是否点击事件,如果长按就isShowBtn==YES,走删除,没按长按或者不按的话就是走另一个页面,isShowBtn==no;
-(void)goNext:(UIButton *)sender{
    
    if (isShowBtn==YES) {
      //走删除页面
        UIButton *btn=(UIButton *)sender;
        [self btnTag:btn.tag];
    }else if (isShowBtn==NO){
    //走另一个页面
        DanPin_ViewController *danPinVC=[[DanPin_ViewController alloc]init];
        danPinVC.smallName=[[dicInfo objectForKey:[allArrys objectAtIndex:sender.tag]] objectForKey:@"huoHao"];
        [self presentViewController:danPinVC animated:YES completion:NULL];
    }   
}
//删除
-(void)btnTag:(int )tag{
    [self deleteAppBtn:tag];
}
//删除实现
- (void)deleteAppBtn:(int)index
{
    NSArray *views = scroll.subviews;
//    NSLog(@"----%@",views);
    __block CGRect newframe;
    for (int i = index; i < [allArrys count]; i++)
    {
        UIView *obj = [views objectAtIndex:i];
        __block CGRect nextframe = obj.frame;
        if (i == index)
        {
            [obj removeFromSuperview];
        }
        else
        {
            for (UIView *v in obj.subviews)
            {
                if ([v isMemberOfClass:[UIButton class]])
                {
                    v.tag = i - 1;
                    break;
                }
            }
            [UIView animateWithDuration:0.6 animations:^
             {
                 obj.frame = newframe;
             } completion:^(BOOL finished)
             {
             }];
        }
        newframe = nextframe;
    }
    
    if ([PlistName isEqualToString:@"dataOne"]) {
        
        [[SavePList sharedInstance]removeBookWithKey:[allArrys objectAtIndex:index] name:@"dataOne"];
       [allArrys removeObjectAtIndex:index];
        [self initZongJia:@"dataOne"];
        

    }else if ([PlistName isEqualToString:@"dataTwo"]){
        
        [[SavePList sharedInstance]removeBookWithKey:[allArrys objectAtIndex:index] name:@"dataTwo"];
        [allArrys removeObjectAtIndex:index];
        [self initZongJia:@"dataTwo"];

    }else if ([PlistName isEqualToString:@"dataThree"]){
        
        [[SavePList sharedInstance]removeBookWithKey:[allArrys objectAtIndex:index] name:@"dataThree"];
        [allArrys removeObjectAtIndex:index];
          [self initZongJia:@"dataThree"];
    }
    
    [self endAnimation];
    
}

//点击取消事件
-(void)oneFinger:(UIPanGestureRecognizer *)gr
{
    [self setCancleFlag];
    [self hideBtn];
}


//长按删除事件
- (void)LongPressGestureRecognizer:(UIGestureRecognizer *)gr
{
    isShowBtn=YES;
    
    if (gr.state == UIGestureRecognizerStateBegan)
    {
        
        if (m_bTransform)
            return;
        
        for (UIView *view in scroll.subviews)
        {
            view.userInteractionEnabled = YES;
            for (UIView *v in view.subviews)
            {
                if ([v isMemberOfClass:[UIImageView class]])
                    [v setHidden:NO];
            }
        }
        m_bTransform = YES;
        [self BeginWobble];
    }
    //判断师傅要全部删除
    if ([ret isEqualToString:@"1"]) {
        guanZhuBtn1.hidden=YES;
        removeBtn1.hidden=NO;
       
        
    }else if ([ret isEqualToString:@"2"]){
        guanZhuBtn2.hidden=YES;
        removeBtn2.hidden=NO;

        
    }else if ([ret isEqualToString:@"3"]){
        guanZhuBtn3.hidden=YES;
        removeBtn3.hidden=NO;

    }
    
}
-(void)BeginWobble
{
//    NSAutoreleasePool* pool=[NSAutoreleasePool new];
    for (UIView *view in scroll.subviews)
    {
        srand([[NSDate date] timeIntervalSince1970]);
        float rand=(float)random();
        CFTimeInterval t=rand*0.0000000001;
        [UIView animateWithDuration:0.1 delay:t options:0  animations:^
         {
             //             view.transform=CGAffineTransformMakeRotation(-0.05);
         } completion:^(BOOL finished)
         {
             [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionAllowUserInteraction  animations:^
              {
                  //                  view.transform=CGAffineTransformMakeRotation(0.05);
              } completion:^(BOOL finished) {}];
         }];
    }
//    [pool release];
}

-(void)EndWobble
{
//    NSAutoreleasePool* pool=[NSAutoreleasePool new];
    for (UIView *view in scroll.subviews)
    {
        [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState animations:^
         {
             view.transform=CGAffineTransformIdentity;
             for (UIView *v in view.subviews)
             {
                 if ([v isMemberOfClass:[UIImageView class]])
                     [v setHidden:YES];
             }
         } completion:^(BOOL finished) {}];
    }
//    [pool release];
}

//设置取消设置delegte的image按钮
-(void)setCancleFlag{
    isShowBtn=NO;
    if(m_bTransform==NO)
        return;
    
    for (UIView *view in scroll.subviews)
    {
        view.userInteractionEnabled = YES;
        for (UIView *v in view.subviews)
        {
            if ([v isMemberOfClass:[UIImageView class]])
                [v setHidden:YES];
        }
    }
    m_bTransform = NO;
    [self EndWobble];
}

5 ipad的实现popView实现,还有就是定制pop的颜色

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface PCPopoverController : UIPopoverController

@property (readonly) UIColor *tintColor;

- (id)initWithContentViewController:(UIViewController *)viewController andTintColor: (UIColor *)tintColor;

@end

//
//  PCPopoverController.m
//  PCPopoverControllerTests
//
//  Created by Patrick Perini on 5/16/12.
//  Licensing information available in README.md
//

#import "PCPopoverController.h"

#pragma mark - Internal Constants
CGFloat const contentInset = 10.0;
CGFloat const capInset = 25.0;
CGFloat const arrowHeight = 15.0;
CGFloat const arrowBase = 24.0;

@interface PCPopoverControllerBackgroundView : UIPopoverBackgroundView
{
    UIImageView *borderImageView;
    UIImageView *arrowImageView;
}

+ (UIColor *)currentTintColor;
+ (void)setCurrentTintColor: (UIColor *)tintColor;

@end

@implementation PCPopoverControllerBackgroundView

#pragma mark - Internal Class Variables
static UIColor *currentTintColor;

#pragma mark - Initializers
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame: frame];
    if (!self)
        return nil;
    
    UIGraphicsBeginImageContext(CGSizeMake(60, 60));
    
    UIBezierPath *borderPath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(0, 0, 60, 60)
                                                          cornerRadius: 8];
    [currentTintColor setFill];
    [borderPath fill];
    
    UIImage *borderImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    UIEdgeInsets capInsets = UIEdgeInsetsMake(capInset, capInset, capInset, capInset);
    borderImageView = [[UIImageView alloc] initWithImage: [borderImage resizableImageWithCapInsets: capInsets]];
    
    borderImageView.layer.shadowColor = [UIColor blackColor].CGColor;
    borderImageView.layer.shadowOpacity = .4;
    borderImageView.layer.shadowRadius = 2;
    borderImageView.layer.shadowOffset = CGSizeMake(0, 2);
    
    UIGraphicsBeginImageContext(CGSizeMake(25, 25));
    
    UIBezierPath *arrowPath = [UIBezierPath bezierPath];
    [arrowPath moveToPoint: CGPointMake(12.5, 0)];
    [arrowPath addLineToPoint: CGPointMake(25, 25)];
    [arrowPath addLineToPoint: CGPointMake(0, 25)];
    [arrowPath addLineToPoint: CGPointMake(12.5, 0)];
    
    [currentTintColor setFill];
    [arrowPath fill];
    
    UIImage *arrowImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    arrowImageView = [[UIImageView alloc] initWithImage: arrowImage];
    
    arrowImageView.layer.shadowColor = [UIColor blackColor].CGColor;
    arrowImageView.layer.shadowOpacity = .4;
    arrowImageView.layer.shadowRadius = 2;
    arrowImageView.layer.shadowOffset = CGSizeMake(0, 1);
    arrowImageView.layer.masksToBounds = YES;
    
    [self addSubview: borderImageView];
    [self addSubview: arrowImageView];
    
    return self;
}

#pragma mark - Class Accessors and Mutators
+ (UIColor *)currentTintColor
{
    return currentTintColor;
}

+ (void)setCurrentTintColor:(UIColor *)tintColor
{
    currentTintColor = tintColor;
}

#pragma mark - Class Handlers
+ (UIEdgeInsets)contentViewInsets
{
    return UIEdgeInsetsMake(contentInset, contentInset, contentInset, contentInset);
}

+ (CGFloat)arrowHeight
{
    return arrowHeight;
}

+ (CGFloat)arrowBase
{
    return arrowBase;
}
+ (BOOL)wantsDefaultContentAppearance{
    return NO;
}
#pragma mark - View Handlers
@synthesize arrowOffset;
@synthesize arrowDirection;



- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat height = CGRectGetHeight(self.frame);
    CGFloat width = CGRectGetWidth(self.frame);
    CGFloat left = 0;
    CGFloat top = 0;
    CGFloat coordinate = 0;
    CGAffineTransform rotation = CGAffineTransformIdentity;
    
    switch (arrowDirection)
    {
        case UIPopoverArrowDirectionUp:
        {
            top += arrowHeight;
            height -= arrowHeight;
            coordinate = ((CGRectGetWidth(self.frame) / 2.0) + arrowOffset) - (arrowBase / 2.0);
            arrowImageView.frame = CGRectMake(coordinate, 0, arrowBase, arrowHeight);
            break;
        }
            
        case UIPopoverArrowDirectionDown:
        {
            height -= arrowHeight;
            coordinate = ((CGRectGetWidth(self.frame) / 2.0) + arrowOffset) - (arrowBase / 2.0);
            arrowImageView.frame = CGRectMake(coordinate, height, arrowBase, arrowHeight);
            rotation = CGAffineTransformMakeRotation(M_PI);
            break;
        }
            
        case UIPopoverArrowDirectionLeft:
        {
            left += arrowBase - ceil((arrowBase - arrowHeight) / 2.0);
            width -= arrowBase;
            coordinate = ((CGRectGetHeight(self.frame) / 2.0) + arrowOffset) - (arrowHeight / 2.0);
            arrowImageView.frame = CGRectMake(0, coordinate, arrowBase, arrowHeight);
            rotation = CGAffineTransformMakeRotation(-M_PI_2);
            break;
        }
            
        case UIPopoverArrowDirectionRight:
        {
            left += ceil((arrowBase - arrowHeight) / 2.0);
            width -= arrowBase;
            coordinate = ((CGRectGetHeight(self.frame) / 2.0) + arrowOffset) - (arrowHeight / 2.0);
            arrowImageView.frame = CGRectMake(width, coordinate, arrowBase, arrowHeight);
            rotation = CGAffineTransformMakeRotation(M_PI_2);
            break;
        }
    }
    
    borderImageView.frame = CGRectMake(left, top, width, height);
    [arrowImageView setTransform: rotation];
}

@end

@implementation PCPopoverController

#pragma mark - Properties
@synthesize tintColor;

#pragma mark - Initializers
- (id)initWithContentViewController:(UIViewController *)viewController
{
    self = [self initWithContentViewController: viewController
                                  andTintColor: [UIColor whiteColor]];
    return self;
}

- (id)initWithContentViewController:(UIViewController *)viewController andTintColor:(UIColor *)aTintColor
{
    self = [super initWithContentViewController: viewController];
    if (!self)
        return nil;
    
    [super setPopoverBackgroundViewClass: [PCPopoverControllerBackgroundView class]];
    tintColor = aTintColor;
    
    return self;
}

#pragma mark - Overriders
- (void)setPopoverBackgroundViewClass:(Class)popoverBackgroundViewClass {}

- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
{
    @synchronized(self)
    {
        [[PCPopoverControllerBackgroundView class] setCurrentTintColor: tintColor];
        [super presentPopoverFromRect: rect inView: view permittedArrowDirections: arrowDirections animated: animated];
    }
}

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
{
    @synchronized(self)
    {
        [[PCPopoverControllerBackgroundView class] setCurrentTintColor: tintColor];
        [super presentPopoverFromBarButtonItem: item permittedArrowDirections: arrowDirections animated: animated];
    }
}

@end

用的时候直接调用就可以了, 

  UIViewController *viewControllerPick=[[UIViewController alloc]init];
    popView=[[PCPopoverController alloc]initWithContentViewController:viewControllerPick andTintColor:[UIColor whiteColor]];
    [popView setPopoverContentSize:CGSizeMake(200, 185) animated:YES];
    popView.delegate=self;

一个页面多个popview的实现根据textfield的  tag 实现

-(void)textFieldDidBeginEditing:(UITextField *)textField{

 CGRect rect=[self.view convertRect:textField.frame fromView:textField.superview];
        [popView presentPopoverFromRect:rect inView:self.view permittedArrowDirections:
         UIPopoverArrowDirectionLeft animated:YES];

}

popview里面添加tableview的实现多选单选,全选

实现全选按钮或取消全选按钮,设置bool值点击

allSelectFlag=YES;这块设置bool
                for (int row=0; row<20; row++) {这块是显示可见的cell的点击按钮,所以为显示的cell无法全选,所以就需要设置bool值做判断,这样就可以全选了,
                    UITableViewCell *oneCell =  (UITableViewCell *)[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]];
                    oneCell.accessoryType = UITableViewCellAccessoryCheckmark;
                }   

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell;

        NSString *identity=[NSString stringWithFormat:@"%d%d",indexPath.section,indexPath.row];
        
        cell=[tableView dequeueReusableCellWithIdentifier:identity];
        if (cell==nil) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity];
            cell.selectionStyle=UITableViewCellSelectionStyleGray;
        }
        cell.textLabel.font=[UIFont systemFontOfSize:13];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
        cell.textLabel.text=[aryyYears objectAtIndex:indexPath.row];
        if (allSelectFlag==YES) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        if (allSelectFlag==NO) {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
tableview的多选实现和单选实现

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *oneCell = [tableView cellForRowAtIndexPath: indexPath];
    
   
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    UITextField *textField;
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if([typePick isEqualToString:@"0"]){
        //多选
         textField=(UITextField *)[self.view viewWithTag:1000];
        if (oneCell.accessoryType == UITableViewCellAccessoryNone) {
            
            oneCell.accessoryType = UITableViewCellAccessoryCheckmark;
            NSString *aaa=[aryyYears objectAtIndex:indexPath.row];

  //NSString 字符串的实现添加和删除某段字符串方法
            [YearString appendString:[NSString stringWithFormat:@"%@,",[aaa substringToIndex:aaa.length-1]]];
            [findString appendString:[NSString stringWithFormat:@"%@,",[aryyYears objectAtIndex:indexPath.row]]];

        } else{
            oneCell.accessoryType = UITableViewCellAccessoryNone;
              NSString *aaa=[aryyYears objectAtIndex:indexPath.row];
            [YearString deleteCharactersInRange:[YearString rangeOfString:[NSString stringWithFormat:@"%@,",[aaa substringToIndex:aaa.length-1]]]];
               [findString deleteCharactersInRange:[findString rangeOfString:[NSString stringWithFormat:@"%@,",[aryyYears objectAtIndex:indexPath.row]]]];
        }
        textField.text=findString;
        单选实现

  // NSArray *arry=[tableView visibleCells];
        for (UITableViewCell *cell in arry) {
            [cell setAccessoryType:UITableViewCellAccessoryNone];
        }
        [[tableView cellForRowAtIndexPath:indexPath]setAccessoryType:UITableViewCellAccessoryCheckmark];
    }
}

字符串实现追加字符串和根据多选实现的删除方法

1  appendString:字符串的追加

2 字符串的删除 :deleteCharactersInRange:[findString rangeOfString:@"sdsds"]

3 字符串的截掉后面几位[aaa substringToIndex:aaa.length-1]

字符串还有很多操作方法,有待学习

以上目前就是想到的新项目中的问题,其实还有许多问题,没写出来,等有时间好好总结下,

 

posted on 2013-09-02 16:47  songbai  阅读(533)  评论(0编辑  收藏  举报