如何垂直和水平滚动UI tableview? [英] How to scroll UI tableview vertically and horizontally?

查看:50
本文介绍了如何垂直和水平滚动UI tableview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有表格视图,每一行都有长文本,因此可以滚动整个表格,以便用户可以读取整个文本

i have table view in my app and each row have long text so its possible to scroll whole table so user can read entire text

我也正在使用以下代码来设置我的单元格

also i am using following code to set up my cell

-

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

//buttonCount=0;    
static NSString *CellIdentifier = @"Cell";    
static NSUInteger const kLeftLabel = 100;    
static NSUInteger const  kRightLabel = 101;     
row = [indexPath row];      
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    
if (cell == nil)       
{    
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];   
CGRect leftFrame = CGRectMake(2, 5, 45, 30);  
CGRect rightFrame = CGRectMake(50, 5, 400, 30);  
left = [[[UILabel alloc]initWithFrame:leftFrame]autorelease];  
left.tag = kLeftLabel;  
left.font = [UIFont systemFontOfSize:13];  
[cell.contentView addSubview:left];  
right = [[[UILabel alloc]initWithFrame:rightFrame]autorelease];  
right.tag=kRightLabel;  
right.font = [UIFont systemFontOfSize:13];  
[cell.contentView addSubview:right];  

}    
else {    
left = (UILabel*)[cell.contentView viewWithTag:kLeftLabel];  
right=(UILabel*)[cell.contentView viewWithTag:kRightLabel];  

}     
left.text =[secondSplitArrayValue objectAtIndex:row];  
right.text=[splitArrayValue objectAtIndex:row];  

if (indexPath.row == 0)   
{  
[cell setSelectionStyle:UITableViewCellSelectionStyleNone ];  

}  

return cell;  
}

通过使用上面的代码,我有两列,因此第一列的文本很小,但是第二列的文本很大,要阅读,我想水平滚动它.

by use of above code i have two column so 1st column have small text but 2nd is very much big and to read i want to scroll it horizotally.

我希望有人能解决这个问题.

i hope some one will solve this problem.

先谢谢您

推荐答案

要解决您的问题,无需修改表格视图的滚动,您可以通过以下代码来实现...通过使用此代码,您可以显示您的文字在表格视图单元格的默认标签中以多行形式显示.

To solve your problem there is no need to modify scrolling of table view you can do it by following code... by using this code you can show ur text in multiline in the default label of table view cell.

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

    static NSString *CellIdentifier = @"MyCell";

    UITableViewCell *cell =(UITableViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

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

    cell.textLabel.numberOfLines = 0;
    cell.textLabel.text = @"Its for testing. Its for testing. Its for testing. Its for testing. Its for testing. Its for testing. Its for testing. Its for testing. Its for testing. Its for testing. Its for testing. ";

    return cell;
}

这篇关于如何垂直和水平滚动UI tableview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆