ios


Swift PickerView with custom tableViewCell.xib


I am messing around with swift and i am stuck in creating an UIPickerView connection with a custom TableViewCell.xib. The functionality i want is the following: when i press the switch button a pickerView appears that lets me select a month which will appear instead of the "Select Month" label. I don't really understand where should i create the outlets.
Cell Xib
Main StoryBoard
class TableViewCell: UITableViewCell {
#IBOutlet weak var leftImage: UIImageView!
#IBOutlet weak var label: UILabel!
#IBOutlet weak var rightImage: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func commonInit(_ imageName1: String, _ imageName2: String, text: String){
leftImage.image = UIImage(named: imageName1)
rightImage.image = UIImage(named: imageName2)
label.text = text
}
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let textData = ["Select Month"]
let datePicker = UIDatePicker()
#IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "UiTableView"
tableView.delegate = self
tableView.dataSource = self
let nibName = UINib(nibName: "TableViewCell", bundle: nil)
tableView.register(nibName, forCellReuseIdentifier: "tableViewCell")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return textData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableViewCell", for: indexPath) as! TableViewCell
cell.commonInit("facebook", "twitter", text: textData[indexPath.item])
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 170
}
func createDatePicker(){
let toolBar = UIToolbar()
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
toolBar.setItems([doneButton], animated: false)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Open up the Cell Xib file and choose from the Menu, View>Assistand Editor>Show Assistant Editor. Once the Assistant Editor is open you can open the TableViewCell class. Control Drag from the 3 controls in the XIB in Interface builder to the corresponding entry in the file. Once over the entry such as #IBOutlet weak var leftImage: UIImageView!, it will highlight. Release the mouse and the connection will be established.
It is actually a little bit easier to not type the line with the outlet declaration in the class first. In this case, when you control drag from ID you position the mouse over an empty line and a dialog box appears where you can declare the outlet. It creates the connection at the same time.

Related Links

Publishing issue, Callkit is included even we are not using it
How to get crash information from a TestFlight launched app?
Parse: Updating relation on user in Local Datastore
iOS 10, Local notification show when app is in forground?
What is the reason for this UITableView not showing up on my view controller?
Xcode inserted fileprivate functions after updating to Swift 3 [duplicate]
Xamarin ios UItableView Empty rows at top using Task Scheduler in background
How to test iOS app's localization on a real device when using appium?
How to prevent NSInternalInconsistencyException with Realm and UICollectionView
(Swift, EarlGrey) move slider to the middle
How can I make physicBody dynamic only on needed levels?
check if item exists in core data EFFICIENTLY
How to continue in the background a connection started with NSURLConnection in the foreground?
Using delegate methods to save a custom cell textfield
Move a UILabel when changing to landscape
“show” segue inside UITabBarController & UINavigationController does not push

Categories

HOME
asp.net-mvc
validation
simulated-annealing
lua
azure-search
load
outlook
middleware
open-source
textbox
gluon
windows-server-2012-r2
freebsd
entity
librsvg
graphengine
html5-video
avr
group-by
watchservice
lazy-loading
w2ui
html-email
media-source
aikau
ibm-datapower
hough-transform
jqplot
bitcode
toolbar
android-arrayadapter
expression-trees
toastr
ollydbg
uistoryboardsegue
sinon
jpype
mdanalysis
codeigniter-hmvc
couchbase-lite
adal.js
sections
mrtg
notimplementedexception
hipi
gpt
getelementbyid
zenity
itamae
xceed
finalcut
android-number-picker
uploadify
webmail
flotr2
illegalstateexception
egl
genetic
greenfoot
readline
polygons
chunk-templates
gulp-protractor
node-orm2
devenv
structured-programming
sslv3
getuikit
targetinvocationexception
newsql
android-tablelayout
physx
xsltforms
confirmation
blueprint
xidel
execcommand
transport-stream
semantic-markup
emacs-jedi
ccombobox
google-chrome-frame
progressdialog
hogan.js
applaud
code-structure
j#
objcopy
rails-3.1
winamp
case-tools

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App