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


문제 설명

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

tableviewcontroller에서 셀 사이의 간격을 변경하려면 어떻게 해야 하나요?. Swift를 사용하는 응용 프로그램이 있습니다. 잘 작동하는 tableviewcontroller를 추가했습니다. 이제 내 문제는 작동하지 않는 셀 사이의 공간을 변경하려고하면입니다. 다음 코드를 시도했습니다.

 override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) ‑> CGFloat {
        return 10; // space b/w cells
    }

문제가 무엇인지 찾는 데 도움을 주시겠습니까?

편집 1:

override func numberOfSectionsInTableView(tableView: UITableView) ‑> Int {
        let a = 1;
        return a;
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ‑> Int {
        let a = itemArray.count;
        return a;
    }

참조 솔루션

방법 1:

To use the method you have to change the logic

override func numberOfSectionsInTableView(tableView: UITableView) ‑> Int {
    let a = itemArray.count;
    return a;
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ‑> Int {
    let a = 1;
    return a;
}

and have to change the rowAtIndexPath... too, using indexPath.section instead of indexPath.row, e.g.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ‑> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell")

    cell.titleLabel.text = itemArray[indexPath.section] // if itemArray is [String]

    return cell
}

방법 2:

With Swift 2 you can do spacing between UITableViewCells in this way:

// In this case I returning 140.0. You can change this value depending of your cell
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) ‑> CGFloat {
    return 140.0
}

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    cell.contentView.backgroundColor = UIColor.clearColor()

    let whiteRoundedView : UIView = UIView(frame: CGRectMake(0, 10, self.view.frame.size.width, 120))

    whiteRoundedView.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), [1.0, 1.0, 1.0, 1.0])
    whiteRoundedView.layer.masksToBounds = false
    whiteRoundedView.layer.shadowOffset = CGSizeMake(‑1, 1)

    cell.contentView.addSubview(whiteRoundedView)
    cell.contentView.sendSubviewToBack(whiteRoundedView)
}

방법 3:

You can use layout margin function. This is only for iOS8. Subclass an UITableViewCell and

‑ (UIEdgeInsets)layoutMargins {
    return UIEdgeInsetsMake(10, 0, 10, 0);
}

방법 4:

Hi the easiest way i found is simply change it
FROM :

<div class="snippet" data‑lang="js" data‑hide="false">

override func numberOfSectionsInTableView(tableView: UITableView) ‑> Int {
let a = 1
return a
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ‑&gt; Int {
    let a = itemArray.count
    return a
}</code></pre>

</div>
</div>
</p>

TO:

override func numberOfSectionsInTableView(tableView: UITableView) ‑> Int {
        let a = itemArray.count
        return a
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ‑> Int {
        let a = 1
        return a
    }

AND ADD THIS :

override func tableView(tableView: UITableView, heightForFooterInSection section: Int) ‑> CGFloat {
        return heightOfSpaceBetweenCells
    }

    override func tableView(tableView: UITableView, viewForFooterInSection section: Int) ‑> UIView? {
        let footerV = UIView()
            footerV.backgroundColor = UIColor.clearColor()

            return footerV
    }

(by AmsheerDrizztnekoOrkhan AlizadecekisakurekBen Siso)

참조 문서

  1. How can I change the space between tableview cells ios swift (CC BY‑SA 2.5/3.0/4.0)

#swift2 #uitableview #iOS






관련 질문

재정의된 메서드에 대한 신속한 문서 주석? (Swift documentation comments for overriden methods?)

Swift 2 "Type 'NSCalendarUint'에 'YearCalendarUnit' 멤버가 없습니다" 오류가 발생했습니까? (I got error with in Swift 2 "Type 'NSCalendarUint' has no member 'YearCalendarUnit' "?)

Xcode 7: 사용자 정의 키보드가 시뮬레이터에 표시되지 않음 (Xcode 7: Custom keyboard is not showing in simulator)

게임 데이터를 저장하려고 할 때 오류가 발생했습니다. (Error when trying to save gamedata)

Alamofire에서 캐시된 응답 감지 (Detect cached response in Alamofire)

언래핑 라인을 잡고 잡으시겠습니까? 스위프트 2.0, XCode 7 (Try and catch around unwrapping line? Swift 2.0, XCode 7)

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

.removeFromParent()가 작동하지 않음 (.removeFromParent() not working)

Swift2 UI 테스트 - 요소가 나타날 때까지 대기 (Swift2 UI Test - Wait for Element to Appear)

Swift의 View에 추가한 후 UIBezierPath의 색상을 변경하는 방법은 무엇입니까? (How to change the color of a UIBezierPath after added on View in Swift?)

swift에서 nil 객체와 문자열 연결 (string concatenate with nil object in swift)

포드 파일 없이 MWPhotoBrowser 사용 (Use MWPhotoBrowser without pod file)







코멘트