Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何垂直和水平滚动UI tableview?_Iphone_Objective C_Uitableview_Uiscrollview_Scroll - Fatal编程技术网

Iphone 如何垂直和水平滚动UI tableview?

Iphone 如何垂直和水平滚动UI tableview?,iphone,objective-c,uitableview,uiscrollview,scroll,Iphone,Objective C,Uitableview,Uiscrollview,Scroll,我的应用程序中有表格视图,每行都有长文本,所以可以滚动整个表格,这样用户就可以阅读整个文本 另外,我正在使用以下代码设置我的手机 - 通过使用上面的代码,我有两列,所以第一列有小文本,但第二列非常大,为了阅读,我想水平滚动它 我希望有人能解决这个问题 提前感谢您需要为长文本使用多行标签,并通过在下面的函数中使用长文本进行计算来正确设置长单元格的高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSI

我的应用程序中有表格视图,每行都有长文本,所以可以滚动整个表格,这样用户就可以阅读整个文本

另外,我正在使用以下代码设置我的手机

-

通过使用上面的代码,我有两列,所以第一列有小文本,但第二列非常大,为了阅读,我想水平滚动它

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


提前感谢

您需要为长文本使用多行标签,并通过在下面的函数中使用长文本进行计算来正确设置长单元格的高度

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

有关更多信息,您可以阅读将UITableView放置在UIScrollview中的

以解决您的问题,无需修改表格视图的滚动,您可以通过以下代码完成此操作。。。通过使用此代码,您可以在表视图单元格的默认标签中以多行显示您的文本

- (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;
}

但是从你的案例来看,没有必要做这样的事情,我更愿意根据文本使单元格高度动态变化

只需使用上述代码即可解决您的问题: 您需要在单元格中使用具有TextView的自定义单元格

//计算文本的高度和宽度

CGSize stringSize=[@“需要计算高度和宽度的示例文本”sizeWithFont:[UIFont boldSystemFontOfSize:[YurTextField font]constrainedToSize:CGSizeMake(2309999)lineBreakMode:UILineBreakModeWordWrap]

- (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];
}

 [Over here take TextView calculating the Height & width of String ];
// [add TextView it cells contentView];
 [cell.contentView addSubview:TextView];


return cell;
}


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

    CGSize stringSize = [@"Your sample text whose height & Width need to be calulated" sizeWithFont:[UIFont           boldSystemFontOfSize:[YurTextField font] constrainedToSize:CGSizeMake(230, 9999) lineBreakMode:UILineBreakModeWordWrap];

         return stringSize.height;

}
如果它不能解决你的问题,那么试着使用下面的替代方案

尽管我可以建议您使用ScrollView并将其设置为委托

将UITAbleView作为子视图添加到ScrollView,并根据要滚动的视图大小保持ScrollView的大小

->看法

-->滚动视图


--> UITababyVIEW/P>没有多行是不可能的吗?我知道为什么你不想使用吗?这个方法要好得多,然后让一个表视图滚动到两边。如果用户不得不在两个方向上滚动来阅读整个文本,那就是糟糕的UI设计。字体-size@Jhaliya,因为我有很多行,我正在做我的论文项目,所以我的教授不喜欢它。你知道有些时候你必须遵循其他想法……如果用户可以在横向视图中查看文本,这可能是个好主意。UITableView继承自UIScrollView,再次放置会给你带来麻烦。是的,我尝试添加子视图,但现在我可以但是我看不到我的表视图内容,虽然这可能会起作用,但这将是可怕的UI设计和用户体验-1@Pooja:正如我前面提到的“再次放置会给你带来麻烦”。由于我不知道如何设置代码格式,有没有更好的方法来设置代码格式…(@Ajay,非常感谢你提供的代码,我会尽快通知你

- (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];
}

 [Over here take TextView calculating the Height & width of String ];
// [add TextView it cells contentView];
 [cell.contentView addSubview:TextView];


return cell;
}


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

    CGSize stringSize = [@"Your sample text whose height & Width need to be calulated" sizeWithFont:[UIFont           boldSystemFontOfSize:[YurTextField font] constrainedToSize:CGSizeMake(230, 9999) lineBreakMode:UILineBreakModeWordWrap];

         return stringSize.height;

}