乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      【IOS功能實(shí)現(xiàn)】之:下拉列表

       嘆落花 2015-01-11

      通過網(wǎng)上資料,自己借助資料寫的代碼,這是完全代碼


      //****************************************************************************


      @interface DropDown1 : UIView <UITableViewDelegate,UITableViewDataSource> {

          UITableView *tv;//下拉列表

          NSArray *tableArray;//下拉列表數(shù)據(jù)

          UITextField *textField;//文本輸入框

          BOOL showList;//是否彈出下拉列表

          CGFloat tabheight;//table下拉列表的高度

          CGFloat frameHeight;//frame的高度

      }


      @property (nonatomic,retainUITableView *tv;

      @property (nonatomic,retainNSArray *tableArray;

      @property (nonatomic,retainUITextField *textField;


      @end


      //****************************************************************************


      @implementation DropDown1


      @synthesize tv,tableArray,textField;


      - (void)dealloc

      {

          [tv release];

          [tableArray release];

          [textField release];

          [super dealloc];

      }


      -(id)initWithFrame:(CGRect)frame

      {

          if (frame.size.height<200) {

              frameHeight = 200;

          }else{

              frameHeight = frame.size.height;

          }

          tabheight = frameHeight-30;

          

          frame.size.height = 30.0f;

          

          self=[super initWithFrame:frame];


          if(self){

              showList = NO//默認(rèn)不顯示下拉框

              

              tv = [[UITableView allocinitWithFrame:CGRectMake(030, frame.size.width0)]; 

              tv.delegate = self;

              tv.dataSource = self;  

              tv.backgroundColor = [UIColor grayColor];  

              tv.separatorColor = [UIColor lightGrayColor];  

              tv.hidden = YES;  

              [self addSubview:tv];  


              textField = [[UITextField allocinitWithFrame:CGRectMake(00, frame.size.width30)];

              textField.borderStyle=UITextBorderStyleRoundedRect;//設(shè)置文本框的邊框風(fēng)格

              [textField addTarget:self action:@selector(dropdown) forControlEvents:UIControlEventAllTouchEvents];

              [self addSubview:textField];

              

          }

          return self;

      }

      -(void)dropdown{

          [textField resignFirstResponder];

          if (showList) {//如果下拉框已顯示,什么都不做

              return;

          }else {//如果下拉框尚未顯示,則進(jìn)行顯示

              

              CGRect sf = self.frame;

              sf.size.height = frameHeight;

              

              //dropdownList放到前面,防止下拉框被別的控件遮住

              [self.superview bringSubviewToFront:self];

              tv.hidden = NO;

              showList = YES;//顯示下拉框

              

              CGRect frame = tv.frame;

              frame.size.height = 0;

              tv.frame = frame;

              frame.size.height = tabheight;

              [UIView beginAnimations:@"ResizeForKeyBoard" context:nil]; 

              [UIView setAnimationCurve:UIViewAnimationCurveLinear];  

              self.frame = sf;

              tv.frame = frame;

              [UIView commitAnimations];

          }

      }


      - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

      {

          return 1;

      }


      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

      {

          return [tableArray count];

      }


      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

      {

          static NSString *CellIdentifier = @"Cell";

          

          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

          if (cell == nil) {

              cell = [[[UITableViewCell allocinitWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

          }

          

          cell.textLabel.text = [tableArray objectAtIndex:[indexPath row]];

          cell.textLabel.font = [UIFont systemFontOfSize:16.0f];

          cell.accessoryType = UITableViewCellAccessoryNone;

          cell.selectionStyle = UITableViewCellSelectionStyleGray;

          

          return cell;

      }

      -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

      {

          return 35;

      }

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

      {

          textField.text = [tableArray objectAtIndex:[indexPath row]];

          showList = NO;

          tv.hidden = YES;

          

          CGRect sf = self.frame;
          sf.size.height = 30;
          self.frame = sf;

          CGRect frame = tv.frame;
          frame.size.height = 0;
          tv.frame = frame;

      }


      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

      {

          // Return YES for supported orientations

          return (interfaceOrientation == UIInterfaceOrientationPortrait);

      }


      @end


      //****************************************************************************


      上面的是實(shí)現(xiàn)方法,下面是使用:


       DropDown1 *dd1 = [[DropDown1 allocinitWithFrame:CGRectMake(1010140100)];

       dd1.textField.placeholder = @"請(qǐng)輸入聯(lián)系方式";

       NSArray* arr=[[NSArray alloc]initWithObjects:@"電話",@"email",@"手機(jī)",@"aaa",@"bbb",@"ccc",nil];

       dd1.tableArray = arr;

       [arr release];

       [self.view addSubview:dd1];

       [dd1 release];

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多