UITableView

1、前题条件

1.1 UITableView不能直接加载到窗体中,窗体中首先要加载一个UIView控件,然后才可以添加UITableView

1.2 UITableView需要继续两个协议<UITableViewDelegate,UITableViewDataSource>

两个协议的方法为:

 

--行的数量:

-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 
{
 return [tableArray count];
}

 

 

 

 

--行的定义

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             SimpleTableIdentifier];
    if (cell == nil)
 {
  //默认样式
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier: SimpleTableIdentifier] autorelease];
 }
 
 //文字的设置
 NSUInteger row=[indexPath row];
 cell.textLabel.text=[tableArray objectAtIndex:row];
 
 return cell;
}

 

 

 

2、添加UIView

 

 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320,260)];

//自定识别头及高度
 view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight;
 view.backgroundColor = [UIColor blueColor];

//将view添加到主窗体

[self.view addSubview:view];

 

 

 

3、添加UITableView

 

UITableView  *table1=[[UITableView alloc] initWithFrame:CGRectMake(0, 0.00, 300, 250)];
 table1.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight;
table1.backgroundColor=[UIColor redColor];

//添加到view窗体上

[view addSubview:table1];

 

 table1.delegate=self;
 table1.dataSource=self;

 

 

 

4、取消点击动画

 

 [tableView deselectRowAtIndexPath:indexPath animated:YES];

 

 

5、滚动路径标识,直至指数连续接收器在屏幕上的特定位置

 

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated Parameters  

 

indexPath

索引路径标识在其行的索引,其部分指标表视图行。

scrollPosition

 一个常数,在接收标识表查看行(上,中,下)的相对位置滚动时结束。

animated

是如果你要动画在位置改变,没有是否应立即生效。

 

实例代码:

float height = 216.0;

CGRect frame = m_pTableView.frame;
frame.size = CGSizeMake(frame.size.width, frame.size.height - height);

[UIView beginAnimations:@"Curl"context:nil];//动画开始   
[UIView setAnimationDuration:0.30];   
[UIView setAnimationDelegate:self];  
[m_pTableView setFrame:frame];  
[m_pTableView scrollToRowAtIndexPath:selectedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

[UIView commitAnimations]; 

 

 

 

6、获取选中的列

[转载]IPhone之UITableView

代码如下:

 

for (NSInteger i = 0; i < [[peopleTableView visibleCellscount]; i++) 

{

UITableViewCell *cell = [[peopleTableView visibleCells]objectAtIndex:i];

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) //将勾选的人员添加到列表中

{

Item *item = (Item *)[NextPeopleList.SelectList objectAtIndex:i];

[peopleList addObject:item];

isCheck = TRUE;

}

}

 

 

 

7、Cell将要显示时事件

 

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

{

if (indexPath.row % 2 == 0) {

cell.backgroundColor = DarkColor;

}else {

cell.backgroundColor = LightColor;

}

 

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值