Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all 593 articles
Browse latest View live

How create a MonthPicker in SwiftUI?

$
0
0

I would like display a date picker contained only month and year.

The default DatePicker display day, month and year. It's not possible to remove day and set a min and max date.

How generate this MonthPicker in swiftUI ? LIke this :

enter image description here


Option selected from one of the picker view duplicates in another picker view Swift

$
0
0

I've a survey with 8 questions and each question has a picker view with options loading from the server. This is in the UI Collection View. The survey works fine upto 5 questions but when we added more than 5, whatever the option we pick for the question 1 gets selected both for question1 and 6. same with question 2 and 3 which returns Index out of range error and I see only 5 answers instead of 8. Any help is appreciated.

Here is my code:

 override func collectionView(_ collectionView: UICollectionView,
                                 cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
                                                      for: indexPath) as! QuestionViewCell


        constructQuestionViewCell(cell, withQuestion: survey?.questions[indexPath.item])

        return cell
    }


private func constructQuestionViewCell(_ cell: QuestionViewCell, withQuestion question: SurveyQuestion? = nil) {
        cell.questionTitle.text = question?.title
        cell.questionTitle.numberOfLines = 0
        cell.questionTitle.sizeToFit()


if (question?.type == "number_list") {

let options = question?.values ?? ["", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]

let picker = CustomPickerView(frame: .zero, textView: cell.questionResponse, options: options)

cell.questionResponse.inputView = picker

 picker.reloadAllComponents()
       }

}

Can I customize UIPickerView like this?

$
0
0

I have to making UIPickerView.
My designer request like this.
enter image description here

But iOS default UIPickerView is not working like that.
So I think I have to customize UIPickerView.
But is it possible?
I don't know if it's possible to implement it because it's not just different colors.

Is there a way to create separate forms inside each UITableViewCell of a single UITableView?

$
0
0

I want to create a table view where each cell is an individual form. I have been following this approach for the dropdown behavior that I want for the forms.

Also, here is an idea of how I want each cell to look like (collapsed and expanded):

enter image description here

As you can see in the image, I want to be able to include different input methods such as UITextView, UIPickerView, and checkbox. The save button would be used to store the inputs and the send button would be used to save the input and then activate the event (which consists of sending scheduled messages over a period of time). I think my main problem consists of two parts:

  1. How can I add the UIPickerView as an input method inside each cell/form?
  2. How can I handle the input of each cell independently?

Notice that in this question I think I found how to get the input from a cell but I am trying to include the save button inside the cell, which I believe requires a different workaround.

I already know how to work with the input outside of the UITableView but I don't find a way to achieve the dropdown behaviour without it, besides I would have to rewrite the form 4 times.

UIPickerView BarButton Text Color is not change but when click on button then the color is change in objective c

$
0
0

I have issue I have set UIPickerViewBarButton title color to blue but it not give the perfect output but when I click on that button it gives the output means it change the color to blue but I don't want blue color only after click, i want button color blue before click. so how can I do this please help me for this issue . Thank You

enter image description here

Code :-

-(void)SetToolbar
{
    //******* add buttons in toolbar
    self.toolbar=[[UIToolbar alloc]init];
    self.toolbar.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin );
    self.toolbar.frame=CGRectMake(0, self.currencypicker.frame.origin.y, self.currencypicker.frame.size.width, 45);
    self.toolbar.barStyle=UIBarStyleDefault;
    self.toolbar.backgroundColor=[UIColor whiteColor];
    self.toolbar.tintColor=[UIColor blueColor];
    UIBarButtonItem *donebutton=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Btn_DoneClick)];
    //    donebutton.style=UIBarButtonItemStylePlain;
    UIBarButtonItem *cancelbutton=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Btn_CancelClick)];
    UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIView *titleview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 40)];
    titleview.backgroundColor=[UIColor clearColor];
    UILabel *lbltitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 40)];
    lbltitle.backgroundColor=[UIColor clearColor];

    lbltitle.textAlignment=NSTextAlignmentCenter;
    lbltitle.text=@"Payment Type";
    lbltitle.font=[UIFont boldSystemFontOfSize:17.0];
    if(IS_IPAD)
    {
        lbltitle.textColor=[UIColor colorWithRed:113.0/256 green:120.0/256 blue:128.0/256 alpha:1.0];
    }
    else
    {
         lbltitle.textColor=[UIColor blackColor];
    }
    [titleview addSubview:lbltitle];

    UIBarButtonItem *btnAdd=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPaymentClicked)];

    UIBarButtonItem *titlebutton = [[UIBarButtonItem alloc] initWithCustomView:titleview];

    NSArray *items = [NSArray arrayWithObjects:cancelbutton,flex,titlebutton,flex,btnAdd, donebutton, nil];
    [self.toolbar setItems:items animated:NO];
    [self.view addSubview:self.toolbar];
    [self.view bringSubviewToFront:self.pickerView];
    //*******
}

My Delegate DidFinishCode For Navigation :-

[[UINavigationBar appearance] setBarTintColor:FooterBGColor];
     [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
     if (@available(iOS 11.0, *)) {
          [[UINavigationBar appearance] setLargeTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
          [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
     } else {

     }

how we can use 2 UIPicker on the same controller?

$
0
0

Xcode 11 ; Swift 4

How I can use 2 UIPicker on the same controller?

For example in the code below I would like to simple compare value of UIPicker 1 and value of UIPicker2. Thanks!

It should be something like this:

Here my example:

if row1 == 0 && row2 == 0 {     
} 
else if row1 == 0 && row2 == 1 {
} 
else {
}

Real code:

import Foundation
import UIKit

var data1 = ["1", "2", "3", "4", "5"]
var data2 = ["1", "2", "3", "4", "5"]
var Calculator = "0"

class ThirdViewController: UIViewController, UIScrollViewDelegate, UIPickerViewDataSource,        UIPickerViewDelegate {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int     {

   return data1.count

}

    func pickerView(_ pickerView: UIPickerView,
    titleForRow row: Int,
    forComponent component: Int) -> String? {
        return data1[row]
}

@IBOutlet weak var Calculator: UILabel!
@IBOutlet weak var from: UIPickerView!
@IBOutlet weak var to: UIPickerView!

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    if row == 0 {

    } else if row == 1 {

    } else if row == 2 {

    }
}

override func viewDidLoad() {

super.viewDidLoad()
    self.from.dataSource = self
    self.from.delegate = self
    self.to.dataSource = self
    self.to.delegate = self   
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
} 
}

How to change the var when selecting specific value on the Picker (SwiftUI)

$
0
0

I need the useRed value to change to true when selecting 0% in the UI picker (or tipPercentage becomes 4).

I tried the following but the warning "Modifying state during view update, this will cause undefined behavior" shows up and the useRed value remains false:

import SwiftUI

struct ContentView: View {


    @State private var tipPercentage = 2
    @State private var useRed = false

    let tipPercentages = [10, 15, 20, 25, 0]

    var redCheck: Bool {
        if tipPercentage == 4 {
            useRed = true
        } else { useRed = false }
        return useRed
    }


    var body: some View {

        NavigationView {
            Form {

                Section (header: Text("How much tips do you weant to leave?")){
                    Picker("Tip percentage", selection:
                    $tipPercentage) {
                        ForEach(0 ..< tipPercentages.count) {
                            Text("\(self.tipPercentages[$0])%")
                        }

                        }
                      .pickerStyle(SegmentedPickerStyle())
                }.foregroundColor(redCheck ? .red : .black)

            }
        }
    }

How to implement a multiple conversions in pickerView in objective-c

$
0
0

I am trying to create a conversion app. I have three units to convert: temperature (fahrenheit, pounds and miles to their metric counterparts).

I want to use a picker view, but I am having difficulties connecting the pickerView to the functionality and actually selecting each unit.

I have been able to implement this in a segmented control, but would like a pickerView to be able to add more conversions in the future.

Thanks!

ViewControlle.m

#import "ViewController.h"

@interface  ViewController (){
NSArray *devices;
}
@end

//CONVERSIONS

// convert pounds to kilograms
double convertLbsToKgs(double poundsValue){
double kilogramsValue;
kilogramsValue = poundsValue / 2.205;
return kilogramsValue;
}

//convert fahrenheit to celcius
double convertFarenheitToCelcius(double farenheitValue){
double celciusValue;
celciusValue = (farenheitValue - 32) * 0.555;
return celciusValue;
}

//convert miles to kilometers
double convertMilesToKilometers(double milesValue){
double kilometersValue;
kilometersValue = milesValue * 1.609;
return kilometersValue;
}

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

devices = @[@"Pounds", @"Fahernheit", @"Miles"];
self.pickerView.dataSource = self;
self.pickerView.delegate = self;
}

// pickerView datascource & delegate methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
 }

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return devices.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return devices[row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

self.outputTextBox.text = devices[row];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

@end

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIPickerViewDataSource, UIPickerViewDelegate>

@property (weak, nonatomic) IBOutlet UITextField *inputField;
@property (weak, nonatomic) IBOutlet UILabel *outputTextBox;
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;


@end

UIPickerView inside a Custom UITableViewCell not initialising, awakeFromNib() not being called

$
0
0

I'm trying to get a UIPickerView inside a custom UITableViewCell to load. The cell loads fine, and I'm able to pass the data (an array of strings) from the UITableViewController to the custom cell through a delegate but the picker just loads blank. I can't for the life of me figure out why.

This seems to be a similar issue but the suggested solution (namely to reload the components of the UIPickerView after setting the pickerData array in the cellForRowAt method) doesn't seem to work.

Any help or insights greatly appreciated.

Custom Cell with UIPickerView

class GradeSelectionCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewDelegate, ReusableView {

    @IBOutlet var pickerView: UIPickerView!

    var pickerData = [String]()
    var numComponents = Int()    

    override func awakeFromNib() {

   // Initialization code

        self.pickerData = Array<String>()
        self.pickerView.delegate = self
        self.pickerView.dataSource = self
        super.awakeFromNib()

    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return numComponents
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
      return   pickerData.count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        print(pickerData[row])
        return pickerData[row]
        }
    }

extension GradeSelectionCell: PickerSetupDelegate {
    func setupPicker(data: [String], numberOfCompents: Int){
        pickerData = data
        numComponents = numberOfCompents
        print("PickerSetupDelegate Called")
        print("pickerData \(String(describing: pickerData))")

    }
}

cellForRowAt

let cell = tableView.dequeueReusableCell(withIdentifier: "GradeSelectionCell", for: indexPath) as! GradeSelectionCell
cell.setupPicker(data: grades, numberOfCompents: 1)
// cell.pickerView.reloadAllComponents()
return cell

Registering Cell in viewDidLoad

tableView.register(GradeSelectionCell.self, forCellReuseIdentifier: "GradeSelectionCell")

Is it possible to load firebase data to UIPickerViewOptions?

$
0
0

I understand I could have

let pickOptions = ["", "11", "12", "13", "14"].

If I have two data stored under my "post" category on my Firebase:

example:
when I load data in my app, I have

  var post: Post? {
    didSet {
       time1Label.text = post.time1
       time2Label.text = post.time2
    }
  }

Is it possible for me to have

let pickOptions = ["", "\ \Contain post.time1", "\ \ Contain post.time2"]?

Can I programmatically scroll to a desired row in UIPickerView?

$
0
0

By default the first row is highlighted after initializing the UIPickerView. How do i highlight a particular row or scroll to particular row programmatically?

Swift: How to set a default Value of a UIPickerView with three components in Swift?

$
0
0

How do I set the starting row of the picker view in Swift? I see there is a code for Objective C, but I don't understand it. If anyone could explain how I can translate the Objective C code into Swift that would also be fantastic !

Thanks

How to show a UIPicker on click of a text field in a particular table view cell swift?

$
0
0

I am having a table view controller with a custom prototype cell.The prototype cell has one textfield on the left(Heading) and another textfield on the right(Value).

This table view displays various details of a person with Heading on the left and Value on the right.The user can edit 3 fields on this page like Policy Holder, Name and Phone Number.This table view has around 15 rows.

When user wants to edit Policy Holder and when he clicks on the the textfield at right side of Policy Holder I want to show a UIPikcer with two options like Self & Other. Once user selects any one among them it has to be entered into the text field.

And if user wants to edit Phone Number field I want the user to enter only in a specific format like +x (xxx) xxx-xxxx.

How can I do these things.

My Table View UI looks like this

How to make pickerView automatically show a value?

$
0
0

I am having trouble getting my picker view to show an initial value on app launch. The picker views work correctly other than this one issue.

let brand = ["Fox"] let series = ["RC1"]

func numberOfComponents(in cornerPickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ cornerPickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    if brandSelector.isEditing{
        return brand.count
    }
    else {
        return series.count
    }

}

func pickerView(_ cornerPickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    if brandSelector.isEditing{
        return brand[row]
    }
    else {
        return series[row]
    }
}
var brandIndex: Int!
var seriesIndex: Int!

func pickerView(_ cornerPickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    if brandSelector.isEditing{
        brandSelector.text = brand[row]
        brandIndex = row

    }
    else if seriesSelector.isEditing{
        seriesSelector.text = series[row]
        seriesIndex = row

    }
    else{
        return
    }
}

func createPickerView() {
    let pickerView = UIPickerView()
    pickerView.delegate = self
    pickerView.dataSource = self



    brandSelector.inputView = pickerView
    seriesSelector.inputView = pickerView


    let toolBar = UIToolbar()
    toolBar.sizeToFit()
    let doneButton = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(self.dismissKeyboard))
    toolBar.setItems([doneButton], animated: false)
    toolBar.isUserInteractionEnabled = true

    brandSelector.inputAccessoryView = toolBar
    seriesSelector.inputAccessoryView = toolBar

}

I'm sure the answer is something simple, I just can't figure out where and what to add. I have attempted to set an initial value for the brandIndex and seriesIndex but it also didn't work.

How to Solve problem UIPickerView Fatal error: Index out of range [IOS Swift 5.1 Xcode 11.2]

$
0
0

I'm trying to Get the selected value of UIPickerView when running App. But I get error,

Fatal error: Index out of range

I debug by print("selected ==>\(selected)") in numberOfRowsInComponent function. I get value of selected by debugging as 0.

How to solve this problem?

Value From Postman
- Plandate function
http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetPlanDate/2
"[  {    \"PlanDate\": \"26/08/2019\",    \"PlanDateFullFormat\": \"20190826\"  },  {    \"PlanDate\": \"27/08/2019\",    \"PlanDateFullFormat\": \"20190827\"  }]"

- PlanShipment
http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetShipment/2/20190826
"[  {    \"Shipment\": \"4505023278\"  },  {    \"Shipment\": \"4505023279\"  }]"
http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetShipment/2/20190827
"[  {    \"Shipment\": \"4505023244\"  },  {    \"Shipment\": \"4505023274\"  }]"
Return Value From JSON
- Plandate function
http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetPlanDate/2
pplandateCategories ==>["20190826", "20190827"]

- PlanShipment
http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetShipment/2/20190827
getpShipmentDCPlanData ==>["4505023244", "4505023274"]
Swift
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
      return 2
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if component == 0 {
            return pPlandateCategories.count
        }else{
            let selected = pickerview.selectedRow(inComponent:0)
           return pShipmentCategories[selected].count ———>. Thread 1: Fatal error: Index out of range
        }
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        if component == 0 {
            return pPlandateCategories[row]
        }else{
            let selected = pickerview.selectedRow(inComponent:0)
            return pShipmentCategories[selected][row]
        }
    }

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if component == 0{
            pickerview.reloadComponent(1)

        }else{
            let selected = pickerview.selectedRow(inComponent:0)
//            getpPlanDatePickerView.text = "PlanDate:" + "" + pplandateCategories[selected][row]
            someTextField.text = "Shipment:" + "" + pShipmentCategories[selected][row]
        }
    }
Error when Run Project 
My WebService ==> http://xxx.xxx.xxx.xx/ProjectService/PODService.svc/GetPlanDate/2GetPlanDate/2
Fatal error: Index out of range
2019-12-19 10:55:14.459056+0700 pickerDateAndShipment[782:19020] Fatal error: Index out of range

How to get data selected from UIPickerView and display it on a different View Controller?

$
0
0

I would like to show a user different screens depending on what they choose in a UIPickerView. What would be the best way to implement this? Thanks!

import UIKit

class SelectKitViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {


    @IBOutlet weak var kitPickerView: UIPickerView!

    let kits = ["Kit 1", "Kit 2"]
    var chosenKit: String?

    override func viewDidLoad() {
        super.viewDidLoad()

        kitPickerView.delegate = self
        kitPickerView.dataSource = self            
    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return kits[row]
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return kits.count
    }
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        let value = kits[row]
        chosenKit = value
    }

    @IBAction func continuePressed(_ sender: Any) {
        performSegue(withIdentifier: "SelectReactionVolume", sender: nil)
    }
}

I would like to perform a segue to another View Controller when continue is pressed. Once the user chooses a kit they will have to enter additional info about the kit selected.

UIPickerView PanGesture is coinciding with Modally presented VC dismiss gesture

$
0
0

I have added simple UIPickerView in PresentedViewController as shown below, but problem is when I am swapping down at red point, Instead of reaction from UIPickerView whole ViewController in coming down.

enter image description here

I went through solutions provided here. https://stackoverflow.com/a/57635168/4614493 But problem is UIPickerView does not provide any function for existing gestures as per my knowledge to avoid other panGestures because of which whole ViewController is coming down.

How may I avoid same, Let me know if something is not clear enough.

I don't think it's required but you may find relevant code in TaskViewController here in my project https://github.com/kautsiitd/Calendar.git

How do I reload/refresh the UIPickerView (with new data array) based on button press?

$
0
0

enter image description here

IF I wanted a picker, for states/provinces, i haven't seen an example, but I mocked up shown above, a picker for US/Can/Mex. wondering can you dynamically switch the NSMutableArray for the UIPickerView and then have it somehow reload each time you click on US/Can/Mex buttons??? How do I go about doing this. What approach do I take. Looking for someone to point a beginner for a clue in the right direction.

Is it possible to use UIPickerView with data from Firebase Realtime Database?

$
0
0

I have a firebase database with users, and in my app I want to have a PickerView where you can see all the emails/information on that one user. Is it possible to create this using Xcode?

My Firebase Databse Structure

my code:

ViewController: UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var dropDown: UIPickerView!
    @IBOutlet weak var txtUser: UITextField!

    var list = ["3","2","1"]

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return list.count
    }
    func pickerView(pikcerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
        return list[row]
    }

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        selected = list[row]
        txtUser.text = selected
    }

}

I have just populated the Picker with numbers to see if this works etc. However this is where I want my firebase database to be inserted.

Swift - Paging UICollectionView by cell while keeping the cell horizontally centered

$
0
0

First, not sure if the title is correct or offers the best description but I'm not sure what else to use.

So, i'm working on an app and I reached a section where I got stuck while implementing the UI. Basically, I have a VC (image below) that can segue to its self based on the info I get from a JSON file.

enter image description here

The thing is I need to have a carousel-like menu in the upper side with an undefined number of cells (again, depends on what I get from the JSON file). I decided to go for a UICollectionView for this and I managed to implement the basics without any problem.

But here is the part where I got stuck:

  1. Since the selected cell must ALWAYS be centered, when the first and the last cell gets selected, I need to have an empty space between the cell and the safe area (see the image above).
  2. The scroll needs to be paged. Normally this wouldn't be a problem if the UICollectionView cell would have a width almost equal to the one of the screen but the requirement is to be able to scroll one element at a time (see second screen above).

I tried finding something similar but maybe I'm not looking for the right thing because all I could find was Paging UICollectionView by cells, not screen

Also, to be honest I've never seen an app / UICollectionView with this behaviour.

I posted parts of the code below but it's not really gonna help much since it's just standard UICollectionView methods.

Any suggestions?

class PreSignupDataVC : UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource

@IBOutlet weak var cvQuestions: UICollectionView!

var questionCell : PreSignupDataQuestionCellVC!
var screenData : Array<PreSignupScreenData> = Array<PreSignupScreenData>()
var pvDataSource : [String] = []
var numberOfComponents : Int = 0
var numberOfRowsInComponent : Int = 0
var currentScreen : Int = 1
var selectedType : Int?
var selectedCell : Int = 0
var initialLastCellInsetPoint : CGFloat = 0.0

override func viewDidLoad()
{
    super.viewDidLoad()

    print("PreSignupDataVC > viewDidLoad")

    initialLastCellInsetPoint = (self.view.frame.width - 170)/2
    screenData = DataSingleton.sharedInstance.returnPreSignUpUIArray()[selectedType!].screenData
    numberOfComponents = screenData[currentScreen - 1].controls[0].numberOfComponents!
    numberOfRowsInComponent = screenData[currentScreen - 1].controls[0].controlDataSource.count
    pvDataSource = screenData[currentScreen - 1].controls[0].controlDataSource

    cvQuestions.register(UINib(nibName: "PreSignupDataQuestionCell",
                               bundle: nil),
                         forCellWithReuseIdentifier: "PreSignupDataQuestionCellVC")
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
    print("PreSignupDataVC > collectionView > numberOfItemsInSection")

    return screenData[currentScreen - 1].controls.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
    print("PreSignupDataVC > collectionView > cellForItemAt")

    questionCell = (cvQuestions.dequeueReusableCell(withReuseIdentifier: "PreSignupDataQuestionCellVC",
                                                    for: indexPath) as? PreSignupDataQuestionCellVC)!
    questionCell.vQuestionCellCellContainer.layer.cornerRadius = 8.0
    questionCell.lblQuestion.text = screenData[currentScreen - 1].controls[indexPath.row].cellTitle
    questionCell.ivQuestionCellImage.image = UIImage(named: screenData[currentScreen - 1].controls[indexPath.row].cellUnselectedIcon!)

    return questionCell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
    print("PreSignupDataVC > collectionView > didSelectItemAt")

    numberOfComponents = screenData[currentScreen - 1].controls[indexPath.row].numberOfComponents!
    numberOfRowsInComponent = screenData[currentScreen - 1].controls[indexPath.row].controlDataSource.count
    pvDataSource = screenData[currentScreen - 1].controls[indexPath.row].controlDataSource
    selectedCell = indexPath.row

    pvData.reloadAllComponents()
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets
{
    print("PreSignupDataVC > collectionView > insetForSectionAt")

    return UIEdgeInsets(top: 0.0, left: initialLastCellInsetPoint, bottom: 00.0, right: initialLastCellInsetPoint)
}
Viewing all 593 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>