2017-12-06 4 views
0

Xamarin을 사용하여 Visual Studio에서 채팅으로 Android/IOS 앱을 만들려고합니다. 그리고 채팅 풍선에 문제가 있습니다. 안드로이드는 괜찮아요. 텍스트 뷰를 메시지 컨테이너로 사용합니다. 하지만 IOS에서 나는 문제를 만났습니다. TextView를 사용하면 하얀 사각형 만 나타납니다. 메시지의 목록을 구현하기 위해이 코드IOS에서 다중 행 텍스트에 가장 적합한 텍스트 컨테이너는 무엇입니까

public override void ViewDidLoad(){ 
    _chatsMessagesListAdapter = new MessagesTableSourceClass(chatData._messages); 
    messagesList.Source = _chatsMessagesListAdapter; 
} 

public class MessagesTableSourceClass : UITableViewSource 
    { 
     readonly List<MessageData> _dataList; 
     public MessagesTableSourceClass(List<MessageData> dataList) 
     { 
      _dataList = dataList; 
     } 
     public override nint RowsInSection(UITableView tableview, nint section) 
     { 
      return _dataList.Count; 
     } 
     public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
     { 
OwnerMessageTableViewCell cell = tableView.DequeueReusableCell(MessageTableViewCell.Key) as OwnerMessageTableViewCell ?? OwnerMessageTableViewCell.Create(); 
cell.BindData(_dataList[indexPath.Row]._message, _dataList[indexPath.Row]._image); 
return cell; 
     } 
     public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
     { 
      tableView.DeselectRow(indexPath, true); 
     } 
     public override UIView GetViewForFooter(UITableView tableView, nint section) 
     { 
      return new UIView(); 
     } 
    } 

OwnerMessageTableViewCell.xib와 jQuery과 사용이 간단한 구조 TableViewCell입니다 ->보기 -> 텍스트 뷰

그러나 결과에있는 TableView messagesList 흰색 사각형처럼 표시됩니다

. 아무도이 문제를 해결할 수 있습니까?

여기 OwnerMessageTableViewCell 구현 업데이트

공용 부분 클래스 OwnerMessageTableViewCell :있는 UITableViewCell { 공공 정적 판독 전용 UINib 펜촉 = UINib.FromName ("OwnerMessageTableViewCell"NSBundle.MainBundle); public static readonly NSString Key = 새 NSString ("OwnerMessageTableViewCell"); 공개 OwnerMessageTableViewCell (핸들을 IntPtr) 염기 (핸들) 는 {} 공용 static) (작성 OwnerMessageTableViewCell {창 (OwnerMessageTableViewCell) Nib.Instantiate (NULL, NULL) [0]; } 내부 무효 BindData (문자열 메시지, UIImage 아바타) { messageIcon.Image = avatar; workerIcon.Hidden = false; messageText.Text = message; } }

다음

XIB 파일 내용 여기 VS 디자이너 윈도우의 화면을

업데이트

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> 
    <dependencies> 
     <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/> 
     <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> 
    </dependencies> 
    <objects> 
     <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> 
     <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> 
     <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="252" customClass="OwnerMessageTableViewCell" rowHeight="44"> 
      <rect key="frame" x="0.0" y="0.0" width="240" height="44"/> 
      <autoresizingMask key="autoresizingMask"/> 
      <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="252" id="253"> 
       <rect key="frame" x="0.0" y="0.0" width="240" height="43"/> 
       <autoresizingMask key="autoresizingMask"/> 
       <subviews> 
        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="280" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES" clipsSubviews="YES" image="Images/worker_icon.png"> 
         <rect key="frame" x="190" y="0.0" width="50" height="50"/> 
         <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/> 
         <userDefinedRuntimeAttributes> 
          <userDefinedRuntimeAttribute keyPath="layer.cornerRadius" type="number"> 
           <real key="value" value="25"/> 
          </userDefinedRuntimeAttribute> 
         </userDefinedRuntimeAttributes> 
        </imageView> 
        <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="justified" id="307" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES" text="Message Text here..." editable="NO" selectable="NO"> 
         <rect key="frame" x="0.0" y="0.0" width="182" height="50"/> 
         <autoresizingMask key="autoresizingMask"/> 
         <color key="backgroundColor" colorSpace="calibratedRGB" red="0.094117647058823528" green="0.31372549019607843" blue="0.63921568627450975" alpha="1"/> 
         <fontDescription key="fontDescription" type="system" pointSize="14"/> 
         <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> 
         <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> 
         <inset key="scrollIndicatorInsets" minX="5" minY="5" maxX="5" maxY="5"/> 
         <userDefinedRuntimeAttributes> 
          <userDefinedRuntimeAttribute keyPath="layer.cornerRadius" type="number"> 
           <real key="value" value="15"/> 
          </userDefinedRuntimeAttribute> 
         </userDefinedRuntimeAttributes> 
        </textView> 
        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="384" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES" image="Images/worker_icon.png"> 
         <rect key="frame" x="220" y="30" width="20" height="20"/> 
         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 
        </imageView> 
       </subviews> 
      </tableViewCellContentView> 
      <point key="canvasLocation" x="-132.5" y="-317"/> 
      <connections> 
       <outlet property="messageIcon" destination="280" id="name-outlet-280"/> 
       <outlet property="messageText" destination="307" id="name-outlet-307"/> 
       <outlet property="workerIcon" destination="384" id="name-outlet-384"/> 
      </connections> 
      <color key="backgroundColor" colorSpace="calibratedRGB" red="0.54117647058823526" green="0.54117647058823526" blue="0.54117647058823526" alpha="1"/> 
     </tableViewCell> 
    </objects> 
    <resources> 
     <image name="chat_bg.jpg" width="414" height="648"/> 
    </resources> 
</document> 

design of tableviewcell;

properties;

layout;

+0

rowHeight를 설정할 수 없으며 셀에 textView를 설정하는 방법에 대해 프레임 또는 제한을 지정 했습니까? –

+0

@ColeXia xib 파일 내용을 추가했습니다. 이것 좀보세요. –

+0

@ColeXia 몇 가지 화면을 추가했습니다. 슬라이딩 메뉴 (TextView 대신 Label 사용)와 동일한 모델을 사용하기 때문에 TextView에 관한 모든 것, 그리고 문제없이 작동합니다. –

답변

1

텍스트에 따라 셀 높이를 조정해야합니다.

네이티브 ios에는 여러 가지 해결책이 있습니다. Auto-Sizing Row Height을 살펴 보시기 바랍니다.

단계 :

  1. 가 자동 크기 조정을 가능하게 Estimated RowHeight을 설정하려면 셀 레이아웃을 작동 할 UITextViewContent Hugging PriorityContent Compression Resistance Priority을 수정합니다.

+0

감사합니다. 그것은 내가 필요한 것입니다. 이제는 모두 정상적으로 작동합니다. –

0

텍스트보기의 컨테이너 역할을하는 뷰를 만듭니다. uiview 안에 textview를 추가하십시오. 그런 다음 텍스트보기의 색상을 투명하게 설정하십시오. 텍스트보기가 uiview 안에 올바르게 위치하도록 구속 조건을 설정하십시오. uiview에 모서리 반경을 적용하여 거품처럼 보이게 만듭니다. 포함하는 텍스트에 따라 셀의 높이를 조정해야합니다.

+0

마지막 부분을 제외하고는 이렇게하는 것이 좋습니다. 포함하는 텍스트에 따라 셀의 높이를 조정하는 방법을 알지 못합니다. –