특정 UITableViewCells에 고유한 삽입을 추가하는 방법은 무엇입니까? (How to add unique insets to specific UITableViewCells?)


문제 설명

특정 UITableViewCells에 고유한 삽입을 추가하는 방법은 무엇입니까? (How to add unique insets to specific UITableViewCells?)

insetsContentViewsToSafeArea 속성이 false로 설정된 UITableView가 있습니다. 이렇게 하면 tableView가 너비에 걸쳐 있습니다. 화면의.

셀의 양과 다른 유형은 서버에 의해 구동되므로 tableView의 내용을 알 수 있는 방법이 없습니다.

하고 싶은 것:

특정 셀에만 고유한 삽입을 할당합니다.

스크린샷을 게시할 수 없으므로 간단한 낙서를 만들려고 합니다.

이 세 개의 셀은 모두 동일한 UITableView에 있습니다.

|[가장자리로 이동하는 하나의 셀입니다. ]|

|[여기에 또 하나가 있습니다]|

|‑‑‑‑‑이 셀에는 자체 삽입이 필요합니다‑‑‑‑‑|

질문:

이를 달성하는 가장 좋은 방법은 무엇입니까?

내가 시도한 것:

  • 재정의 layoutMarginsDidChange
  • layoutMargins에 직접 추가하려고 합니다. >cellForRowAtIndexPath...
com/questions/47760732/how‑can‑i‑achieve‑have‑an‑uitableview‑set‑the‑insets‑of‑its‑cells‑without‑sett">재정의</a> layoutMarginsDidChange </li>
  • cellForRowAtIndexPath...
  • </ul>에 layoutMargins를 직접 추가하려고 합니다.com/questions/47760732/how‑can‑i‑achieve‑have‑an‑uitableview‑set‑the‑insets‑of‑its‑cells‑without‑sett">재정의</a> layoutMarginsDidChange </li>
  • cellForRowAtIndexPath...
  • </ul>에 layoutMargins를 직접 추가하려고 합니다.


    참조 솔루션

    방법 1:

    Create a UITableViewCell subclass for the cell with custom insets.

    Then you have 2 options ‑‑

    1. Add a subview to cell's contentView with constraints ‑‑ these will correspond to your desired insets. This view will act as your " pseudo contentView" (add cell content to it)
    2. Play around with contentView's insets. (not sure if it'll work)

    3. </ol>

      I hope this will get you started.

      You can use the cell subclass for all cell cases too if you want ‑‑ with an enum style which you can set in cell for row.

      enum Style {
       case edgeToEdge
       case withInset(inset: UIEdgeInset)
      }
      
      inside cell subclass
      
      var insetStyle: Style = .edgeToEdge {
         didSet {
            //update the constraints of the pseudo content view
         }
      }
      

      (by ArielSDHarman Orsay)

      참조 문서

      1. How to add unique insets to specific UITableViewCells? (CC BY‑SA 2.5/3.0/4.0)

    #uitableview #XCode #objective-c #swift #iOS






    관련 질문

    레코드 삭제 중 오류 발생, 포착되지 않은 예외 'NSInternalInconsistencyException'으로 인해 앱 종료 (error while deleting records,Terminating app due to uncaught exception 'NSInternalInconsistencyException')

    IOS 7에서 편집 상태의 셀을 반환하는 dequeueReusableCellWithIdentifier (dequeueReusableCellWithIdentifier returning cells in editing state in IOS 7)

    UITableViewCell 탭 호버 (UITableViewCell tap hover)

    ios swift tableview 셀 사이의 공간을 어떻게 변경할 수 있습니까? (How can I change the space between tableview cells ios swift)

    테이블 뷰 셀을 선택할 때 뷰 컨트롤러를 푸시할 수 없습니다. (Can't push my view controller when I select a table view cell)

    셀이 선택되면 UIImageView가 사라지지만 UILabel은 사라지지 않습니다. (UIImageView disappears but not UILabel when cell is selcted)

    UITableView의 테두리를 설정하는 방법은 무엇입니까? (How to set a border for UITableView?)

    plist에서 특정 데이터를 가져오는 UITableView(탐색 템플릿을 사용하지 않음) (UITableView (not using Navigation Template) getting specific data from plist)

    searchBar의 일반 텍스트 버튼에 액세스하는 방법은 무엇입니까? (How to access searchBar's clear text button?)

    'NSInternalInconsistencyException', 이유: '범위를 벗어난 섹션(0)에 대한 행 수를 요청했습니다.' ('NSInternalInconsistencyException', reason: 'Requested the number of rows for section (0) which is out of bounds.')

    UITableViewCell에서 키보드 탭을 숨기는 UITapGestureRecognizer (UITapGestureRecognizer to hide keyboard taps on UITableViewCell)

    특정 UITableViewCells에 고유한 삽입을 추가하는 방법은 무엇입니까? (How to add unique insets to specific UITableViewCells?)







    코멘트