I want to position top UIView on top of UITableView using SnapKitHow can I disable the UITableView selection?Using Auto Layout in UITableView for dynamic cell layouts & variable row heightsWhy is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7How to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsUpdate or reload UITableView after completion of delete action on detail viewTableView not displaying text with JSON data from API callcannot convert value of type [Struct] to type [string] in coercion swiftSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift

Can Brexit be undone in an emergency?

Can one guy with a duplicator trigger a nuclear apocalypse?

Why are there two bearded faces wearing red hats on my stealth bomber icon?

Strength of Female Chimpanzees vs. Male Chimpanzees?

Hobby function generators

What the did the controller say during my approach to land (audio clip)?

Minimize taxes now that I earn a living wage

How can I check that parent has more than 1 child?

If people's daily habits are reliable then why is the stock market so unpredictable?

What's the purpose of autocorrelation?

How long to get a new passport in the US?

Exam design: give maximum score per question or not?

What exactly is a web font, and what does converting to one involve?

Shortcode under a Shortcode Multiple times Possible?

Is this adjustment to the Lucky feat underpowered?

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Does Mage Hand give away the caster's position?

Secondary characters in character-study fiction

merging certain list elements

Did slaves have slaves?

Whence comes increasing usage of "do" for "have" in ordering food?

Why does Canada require a minimum rate of climb for ultralights of 300 ft/min?

(How long) Should I indulge my new co-workers?

Do household ovens ventilate heat to the outdoors?



I want to position top UIView on top of UITableView using SnapKit


How can I disable the UITableView selection?Using Auto Layout in UITableView for dynamic cell layouts & variable row heightsWhy is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7How to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsUpdate or reload UITableView after completion of delete action on detail viewTableView not displaying text with JSON data from API callcannot convert value of type [Struct] to type [string] in coercion swiftSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm written in snapkit for UI render. I have not use storyboard or nib files.



I want to position top UIView on top of UITableView using SnapKit.



How to write it?



Below is my written code



swift
import UIKit
import SnapKit

class ViewController: UIViewController


var data: [String] = []
var tableView = UITableView()
var subView = UIView()
var label = UILabel()


override func viewDidLoad()
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
label.text = "Hello?"
self.view.addSubview(self.tableView)
self.tableView.addSubview(self.subView)
self.subView.addSubview(self.label)
self.subView.backgroundColor = .gray

self.tableView.snp.makeConstraints make in
make.edges.equalToSuperview()


self.subView.snp.makeConstraints make in
make.top.width.equalTo(self.tableView)
make.centerX.equalTo(self.tableView)
make.height.equalTo(200)

self.label.snp.makeConstraints make in
make.centerX.centerY.equalTo(self.subView)

for i in 0...100
data.append("(i)")

self.tableView.reloadData()






override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()



extension ViewController: UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return self.data.count


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let element = self.data[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "comicListCell") ?? UITableViewCell(style: .normal, reuseIdentifier: "comicListCell")
cell.textLabel?.text = element
return cell




extension ViewController: UITableViewDelegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
print(self.data[indexPath.row])




My code :
enter image description here



I want it!:
enter image description hereenter image description here



UIView must placed into UITableView children !!



Sorry my bad english..



Thanks for reading










share|improve this question


























  • Why dont you set the view as the TableHeaderView?. would be much easier

    – Scriptable
    Mar 28 at 14:10

















0















I'm written in snapkit for UI render. I have not use storyboard or nib files.



I want to position top UIView on top of UITableView using SnapKit.



How to write it?



Below is my written code



swift
import UIKit
import SnapKit

class ViewController: UIViewController


var data: [String] = []
var tableView = UITableView()
var subView = UIView()
var label = UILabel()


override func viewDidLoad()
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
label.text = "Hello?"
self.view.addSubview(self.tableView)
self.tableView.addSubview(self.subView)
self.subView.addSubview(self.label)
self.subView.backgroundColor = .gray

self.tableView.snp.makeConstraints make in
make.edges.equalToSuperview()


self.subView.snp.makeConstraints make in
make.top.width.equalTo(self.tableView)
make.centerX.equalTo(self.tableView)
make.height.equalTo(200)

self.label.snp.makeConstraints make in
make.centerX.centerY.equalTo(self.subView)

for i in 0...100
data.append("(i)")

self.tableView.reloadData()






override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()



extension ViewController: UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return self.data.count


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let element = self.data[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "comicListCell") ?? UITableViewCell(style: .normal, reuseIdentifier: "comicListCell")
cell.textLabel?.text = element
return cell




extension ViewController: UITableViewDelegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
print(self.data[indexPath.row])




My code :
enter image description here



I want it!:
enter image description hereenter image description here



UIView must placed into UITableView children !!



Sorry my bad english..



Thanks for reading










share|improve this question


























  • Why dont you set the view as the TableHeaderView?. would be much easier

    – Scriptable
    Mar 28 at 14:10













0












0








0








I'm written in snapkit for UI render. I have not use storyboard or nib files.



I want to position top UIView on top of UITableView using SnapKit.



How to write it?



Below is my written code



swift
import UIKit
import SnapKit

class ViewController: UIViewController


var data: [String] = []
var tableView = UITableView()
var subView = UIView()
var label = UILabel()


override func viewDidLoad()
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
label.text = "Hello?"
self.view.addSubview(self.tableView)
self.tableView.addSubview(self.subView)
self.subView.addSubview(self.label)
self.subView.backgroundColor = .gray

self.tableView.snp.makeConstraints make in
make.edges.equalToSuperview()


self.subView.snp.makeConstraints make in
make.top.width.equalTo(self.tableView)
make.centerX.equalTo(self.tableView)
make.height.equalTo(200)

self.label.snp.makeConstraints make in
make.centerX.centerY.equalTo(self.subView)

for i in 0...100
data.append("(i)")

self.tableView.reloadData()






override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()



extension ViewController: UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return self.data.count


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let element = self.data[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "comicListCell") ?? UITableViewCell(style: .normal, reuseIdentifier: "comicListCell")
cell.textLabel?.text = element
return cell




extension ViewController: UITableViewDelegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
print(self.data[indexPath.row])




My code :
enter image description here



I want it!:
enter image description hereenter image description here



UIView must placed into UITableView children !!



Sorry my bad english..



Thanks for reading










share|improve this question
















I'm written in snapkit for UI render. I have not use storyboard or nib files.



I want to position top UIView on top of UITableView using SnapKit.



How to write it?



Below is my written code



swift
import UIKit
import SnapKit

class ViewController: UIViewController


var data: [String] = []
var tableView = UITableView()
var subView = UIView()
var label = UILabel()


override func viewDidLoad()
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
label.text = "Hello?"
self.view.addSubview(self.tableView)
self.tableView.addSubview(self.subView)
self.subView.addSubview(self.label)
self.subView.backgroundColor = .gray

self.tableView.snp.makeConstraints make in
make.edges.equalToSuperview()


self.subView.snp.makeConstraints make in
make.top.width.equalTo(self.tableView)
make.centerX.equalTo(self.tableView)
make.height.equalTo(200)

self.label.snp.makeConstraints make in
make.centerX.centerY.equalTo(self.subView)

for i in 0...100
data.append("(i)")

self.tableView.reloadData()






override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()



extension ViewController: UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return self.data.count


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let element = self.data[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "comicListCell") ?? UITableViewCell(style: .normal, reuseIdentifier: "comicListCell")
cell.textLabel?.text = element
return cell




extension ViewController: UITableViewDelegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
print(self.data[indexPath.row])




My code :
enter image description here



I want it!:
enter image description hereenter image description here



UIView must placed into UITableView children !!



Sorry my bad english..



Thanks for reading







swift uitableview snapkit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 14:10









Scriptable

14.7k4 gold badges38 silver badges57 bronze badges




14.7k4 gold badges38 silver badges57 bronze badges










asked Mar 28 at 13:55









YUKIYUKIYUKIYUKI

33 bronze badges




33 bronze badges















  • Why dont you set the view as the TableHeaderView?. would be much easier

    – Scriptable
    Mar 28 at 14:10

















  • Why dont you set the view as the TableHeaderView?. would be much easier

    – Scriptable
    Mar 28 at 14:10
















Why dont you set the view as the TableHeaderView?. would be much easier

– Scriptable
Mar 28 at 14:10





Why dont you set the view as the TableHeaderView?. would be much easier

– Scriptable
Mar 28 at 14:10












2 Answers
2






active

oldest

votes


















0
















You could easily add the tableView method:



func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 

if section == 0
return self.subView
else
return UIView.init(frame: CGRect.zero)







share|improve this answer



























  • Thank you for answer! It's working on my project :)

    – YUKIYUKI
    Mar 28 at 14:25











  • I’m glad I helped!

    – marc
    Mar 28 at 14:26











  • If tableview has more than one section. Each section has this subview.

    – Emre Özdil
    Mar 28 at 14:33











  • Please check the edited post.

    – marc
    Mar 28 at 14:36











  • Hmm.. What should I do..?

    – YUKIYUKI
    Mar 28 at 14:37


















1
















You want subview which is sticky header of tableview. Change this line self.tableView.addSubview(self.subView) to
tableView.tableHeaderView = subView.






share|improve this answer

























  • Thank you for answer! I changed original code to tableView.tableHeaderView = subView. then, first scroll page is crashed.. a little scrolling is what i want. Can you tell me why?

    – YUKIYUKI
    Mar 28 at 14:21











  • What is the crash log?

    – Emre Özdil
    Mar 28 at 14:31











  • I solved this problem! I added viewForHeaderInSection delegate..

    – YUKIYUKI
    Mar 28 at 14:32












  • viewForHeaderInSection delegate is not a proper solution.

    – Emre Özdil
    Mar 28 at 14:35













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399361%2fi-want-to-position-top-uiview-on-top-of-uitableview-using-snapkit%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0
















You could easily add the tableView method:



func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 

if section == 0
return self.subView
else
return UIView.init(frame: CGRect.zero)







share|improve this answer



























  • Thank you for answer! It's working on my project :)

    – YUKIYUKI
    Mar 28 at 14:25











  • I’m glad I helped!

    – marc
    Mar 28 at 14:26











  • If tableview has more than one section. Each section has this subview.

    – Emre Özdil
    Mar 28 at 14:33











  • Please check the edited post.

    – marc
    Mar 28 at 14:36











  • Hmm.. What should I do..?

    – YUKIYUKI
    Mar 28 at 14:37















0
















You could easily add the tableView method:



func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 

if section == 0
return self.subView
else
return UIView.init(frame: CGRect.zero)







share|improve this answer



























  • Thank you for answer! It's working on my project :)

    – YUKIYUKI
    Mar 28 at 14:25











  • I’m glad I helped!

    – marc
    Mar 28 at 14:26











  • If tableview has more than one section. Each section has this subview.

    – Emre Özdil
    Mar 28 at 14:33











  • Please check the edited post.

    – marc
    Mar 28 at 14:36











  • Hmm.. What should I do..?

    – YUKIYUKI
    Mar 28 at 14:37













0














0










0









You could easily add the tableView method:



func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 

if section == 0
return self.subView
else
return UIView.init(frame: CGRect.zero)







share|improve this answer















You could easily add the tableView method:



func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 

if section == 0
return self.subView
else
return UIView.init(frame: CGRect.zero)








share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 14:53

























answered Mar 28 at 14:15









marcmarc

6895 silver badges16 bronze badges




6895 silver badges16 bronze badges















  • Thank you for answer! It's working on my project :)

    – YUKIYUKI
    Mar 28 at 14:25











  • I’m glad I helped!

    – marc
    Mar 28 at 14:26











  • If tableview has more than one section. Each section has this subview.

    – Emre Özdil
    Mar 28 at 14:33











  • Please check the edited post.

    – marc
    Mar 28 at 14:36











  • Hmm.. What should I do..?

    – YUKIYUKI
    Mar 28 at 14:37

















  • Thank you for answer! It's working on my project :)

    – YUKIYUKI
    Mar 28 at 14:25











  • I’m glad I helped!

    – marc
    Mar 28 at 14:26











  • If tableview has more than one section. Each section has this subview.

    – Emre Özdil
    Mar 28 at 14:33











  • Please check the edited post.

    – marc
    Mar 28 at 14:36











  • Hmm.. What should I do..?

    – YUKIYUKI
    Mar 28 at 14:37
















Thank you for answer! It's working on my project :)

– YUKIYUKI
Mar 28 at 14:25





Thank you for answer! It's working on my project :)

– YUKIYUKI
Mar 28 at 14:25













I’m glad I helped!

– marc
Mar 28 at 14:26





I’m glad I helped!

– marc
Mar 28 at 14:26













If tableview has more than one section. Each section has this subview.

– Emre Özdil
Mar 28 at 14:33





If tableview has more than one section. Each section has this subview.

– Emre Özdil
Mar 28 at 14:33













Please check the edited post.

– marc
Mar 28 at 14:36





Please check the edited post.

– marc
Mar 28 at 14:36













Hmm.. What should I do..?

– YUKIYUKI
Mar 28 at 14:37





Hmm.. What should I do..?

– YUKIYUKI
Mar 28 at 14:37













1
















You want subview which is sticky header of tableview. Change this line self.tableView.addSubview(self.subView) to
tableView.tableHeaderView = subView.






share|improve this answer

























  • Thank you for answer! I changed original code to tableView.tableHeaderView = subView. then, first scroll page is crashed.. a little scrolling is what i want. Can you tell me why?

    – YUKIYUKI
    Mar 28 at 14:21











  • What is the crash log?

    – Emre Özdil
    Mar 28 at 14:31











  • I solved this problem! I added viewForHeaderInSection delegate..

    – YUKIYUKI
    Mar 28 at 14:32












  • viewForHeaderInSection delegate is not a proper solution.

    – Emre Özdil
    Mar 28 at 14:35















1
















You want subview which is sticky header of tableview. Change this line self.tableView.addSubview(self.subView) to
tableView.tableHeaderView = subView.






share|improve this answer

























  • Thank you for answer! I changed original code to tableView.tableHeaderView = subView. then, first scroll page is crashed.. a little scrolling is what i want. Can you tell me why?

    – YUKIYUKI
    Mar 28 at 14:21











  • What is the crash log?

    – Emre Özdil
    Mar 28 at 14:31











  • I solved this problem! I added viewForHeaderInSection delegate..

    – YUKIYUKI
    Mar 28 at 14:32












  • viewForHeaderInSection delegate is not a proper solution.

    – Emre Özdil
    Mar 28 at 14:35













1














1










1









You want subview which is sticky header of tableview. Change this line self.tableView.addSubview(self.subView) to
tableView.tableHeaderView = subView.






share|improve this answer













You want subview which is sticky header of tableview. Change this line self.tableView.addSubview(self.subView) to
tableView.tableHeaderView = subView.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 14:14









Emre ÖzdilEmre Özdil

3735 silver badges11 bronze badges




3735 silver badges11 bronze badges















  • Thank you for answer! I changed original code to tableView.tableHeaderView = subView. then, first scroll page is crashed.. a little scrolling is what i want. Can you tell me why?

    – YUKIYUKI
    Mar 28 at 14:21











  • What is the crash log?

    – Emre Özdil
    Mar 28 at 14:31











  • I solved this problem! I added viewForHeaderInSection delegate..

    – YUKIYUKI
    Mar 28 at 14:32












  • viewForHeaderInSection delegate is not a proper solution.

    – Emre Özdil
    Mar 28 at 14:35

















  • Thank you for answer! I changed original code to tableView.tableHeaderView = subView. then, first scroll page is crashed.. a little scrolling is what i want. Can you tell me why?

    – YUKIYUKI
    Mar 28 at 14:21











  • What is the crash log?

    – Emre Özdil
    Mar 28 at 14:31











  • I solved this problem! I added viewForHeaderInSection delegate..

    – YUKIYUKI
    Mar 28 at 14:32












  • viewForHeaderInSection delegate is not a proper solution.

    – Emre Özdil
    Mar 28 at 14:35
















Thank you for answer! I changed original code to tableView.tableHeaderView = subView. then, first scroll page is crashed.. a little scrolling is what i want. Can you tell me why?

– YUKIYUKI
Mar 28 at 14:21





Thank you for answer! I changed original code to tableView.tableHeaderView = subView. then, first scroll page is crashed.. a little scrolling is what i want. Can you tell me why?

– YUKIYUKI
Mar 28 at 14:21













What is the crash log?

– Emre Özdil
Mar 28 at 14:31





What is the crash log?

– Emre Özdil
Mar 28 at 14:31













I solved this problem! I added viewForHeaderInSection delegate..

– YUKIYUKI
Mar 28 at 14:32






I solved this problem! I added viewForHeaderInSection delegate..

– YUKIYUKI
Mar 28 at 14:32














viewForHeaderInSection delegate is not a proper solution.

– Emre Özdil
Mar 28 at 14:35





viewForHeaderInSection delegate is not a proper solution.

– Emre Özdil
Mar 28 at 14:35


















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399361%2fi-want-to-position-top-uiview-on-top-of-uitableview-using-snapkit%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript