小编ker*_*rry的帖子

多行UILabel有时省略iOS的最后一行

我在具有动态高度的tableview单元格中使用多行UILabel.问题有时候,UILabel省略了最后一行,而标签高度是完美的,有时它完美地显示每条线.这与此问题类似,但我已经检查过,在我的情况下,行数没有变化.

UILabel没有显示我的所有文字,也没有显示有更多(...)

我正在实施UILabel

  1. 将行设置为0
  2. 设置自动换行

然后我在Label中设置文本.

这是截图.第一个单元格第二个标签显示完整文本,而第三个单元格第二个标签不显示,而标签高度是完美的.

在此输入图像描述

无论是13-14行的长文本还是仅仅2行,都是这种情况.只省略了最后一行,有时也省略了.

我还在表格视图单元格的nib文件中将每个标签的首选宽度设置为220.

我的代码:

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




Message *message = [self.messages objectAtIndex:indexPath.row];

if(indexPath.row % 2 != 0 || indexPath.row == 10)
{
    chatCell = (ChatTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"chatSend"];

    [chatCell.chatMessageLabel setNumberOfLines:0];
    [chatCell.chatNameLabel setNumberOfLines:0];
    [chatCell.chatTimeLabel setNumberOfLines:0];


    chatCell.chatMessageLabel.lineBreakMode = NSLineBreakByWordWrapping;
    chatCell.chatNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    chatCell.chatTimeLabel.lineBreakMode = NSLineBreakByWordWrapping;

    chatCell.chatMessageLabel.text=message.message;
    chatCell.chatNameLabel.text = message.name;
    chatCell.chatTimeLabel.text = message.time;
    chatCell.chatUserImage.image = message.avatar;



}
else
{
    chatCell = (ChatTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"chatReceive"];



    [chatCell.chatMessageLabel setNumberOfLines:0];
    [chatCell.chatNameLabel setNumberOfLines:0];
    [chatCell.chatTimeLabel setNumberOfLines:0];

    chatCell.chatMessageLabel.lineBreakMode = NSLineBreakByWordWrapping;
    chatCell.chatNameLabel.lineBreakMode = …
Run Code Online (Sandbox Code Playgroud)

multiline uitableview uilabel tableviewcell ios

6
推荐指数
0
解决办法
981
查看次数

使用 ActionBar 选项卡在 ViewPager 中的片段更改时重置 SearchView

我已经使用 ActionBar 选项卡实现了两个片段。我正在使用夏洛克碎片。当我开始一个片段时,我在操作栏上创建了一个搜索视图。

问题是:当我在第一个片段上搜索某些内容并且没有关闭搜索视图或删除文本时,我移动到下一个片段,我得到一个折叠的搜索视图,这很好。但是当我再次回到我的第一个片段时,我看到一个像以前一样排序的列表,但搜索视图已折叠。取回原始列表的唯一方法是单击一次搜索视图并将其关闭。

当我移动到第二个片段时如何重置第一个片段上的搜索视图,或者当我来到第一个片段时如何保持搜索视图打开?

任何一种解决方案都可以。

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
 >

<item android:id="@+id/action_search"
    android:title="search"
    android:icon="@drawable/search"
    android:orderInCategory="100"
    android:showAsAction="always|collapseActionView"
    android:actionViewClass="com.actionbarsherlock.widget.SearchView" />

</menu>
Run Code Online (Sandbox Code Playgroud)

这就是我在片段中膨胀的方式

   @Override
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
        {
        super.onCreateOptionsMenu(menu, inflater);

        inflater.inflate(R.menu.main, menu);
        SearchView sv = (SearchView)getActivity().findViewById(R.id.action_search);
          sv.setOnQueryTextListener(new OnQueryTextListener() {
              @Override
              public boolean onQueryTextSubmit(String query) {
                  //...
                  return false;
              }
              @Override
              public boolean onQueryTextChange(String newText) {
                  bindingData.resetData();


                  bindingData.getFilter().filter(newText.toString());
                  return false;
              }
          });
    }
Run Code Online (Sandbox Code Playgroud)

android-fragments searchview

4
推荐指数
2
解决办法
3816
查看次数