xcode控件

本文详细介绍了UITableView的使用方法,包括创建自定义的ViewController类、配置TableView、设置行数和段数、单元格显示逻辑等。此外,还讲解了如何实现行委托、单元格样式调整以及TextField控件的使用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

segmented control控件

sender.selectedsegmentindex

switch 控件
sender.on   sender.off


tableview控件
1.一般自己建一个不含xib的viewcontroller类
2.在tableviewcontroller类中进行表格配置

//这个配置的是需要连续的几个段

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    // Return the number of sections.

    return 2;

}

//每个段需要几行

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

{


    // Return the number of rows in the section.

    return 10;

}


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

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    

    // Configure the cell...

  //如果没有单元,创建单元

    if (!cell) {

        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];

    }

  //单元输出的格式

    cell.textLabel.text=[NSString stringWithFormat :@"%d",indexPath.row];

    return cell;

}


3.在主文件中创建控制器呈现

a.首先要包含table控制器

b.

 

-(void)viewDidAppear:(BOOL)animated{

    //create the tableview controller

    testUITableViewController   *table=[[[testUITableViewController alloc]init]autorelease];

    [self presentModalViewController:table animated:YES];

}


4.tableview的基本属性

    self.tableView.rowHeight=40;

    cell.textLabel.textColor=[UIColor blueColor];

   //这个属性要特别注意他的前提是cell初始化为initWithStyle:UITableViewCellStyleSubtitle

  cell.detailTextLabel.text=@"aaaaa"

//这个是文字前的logo

 

cell.imageView.image=[UIImage imageNamed:@"1"];

//显示文字在列上面的距离差别

cell.indentationlevel=indexpath.row/10;

5.行委托部分

#pragma mark - Table view delegate


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

{

    // Navigation logic may go here. Create and push another view controller.

   

    

    UIAlertView *msgbox=[[[UIAlertView alloc]initWithTitle:@"提示

    message:[NSString stringWithFormat:@"你按下%d",indexPath.row]delegate:nil cancelButtonTitle:@"" otherButtonTitles: nil] autorelease];

    [msgbox show];

}


//willdisplaycell委托方法

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    cell.backgroundColor=[UIColor yellowColor];

}


textfield 控件

//本控件主要讲述的要点是委托及跳出键盘后对键盘按键响应的方法以及对于first responser的应用

1,委托三要素

在h文件控制器旁边添加协议

在didload中指明delegate对象

应用委托中提供的方法

2,对于在本控件作为firstresponser时,我们要求放弃firstresponser权限的方法


 

-(void)PressReturn{

    //if textfield control is the firstresponder

    if ([conText isFirstResponder]) {

        [conText resignFirstResponder];

    }

}


-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [self PressReturn];

    return YES;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值