Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMAlertController textfield access via objc #86

Closed
Blog404DE opened this issue May 21, 2019 · 4 comments
Closed

PMAlertController textfield access via objc #86

Blog404DE opened this issue May 21, 2019 · 4 comments

Comments

@Blog404DE
Copy link
Contributor

Blog404DE commented May 21, 2019

Hi,

i’m using PMAlertController (installed via pod) within a objc app. After some issues with with pods, i’ve removed my pods-folder and reinstalled every pod.

After re-installing i’ve got some build-errors in connection with textFields inside the alert controller.

My (relevant) code:

PMAlertController *quittungDatenAlert = [[PMAlertController alloc] initWithTitle:@"Blahfasel Title“ description:@"Blahfasel-Description:image:nil style:PMAlertControllerStyleWalkthrough];

[quittungDatenAlert addTextField:^(UITextField *textField) {
	[textField setPlaceholder: @"Betrag erhalten von"];
	[textField setKeyboardType:UIKeyboardTypeDefault];
}];

PMAlertAction* alertSend = [[PMAlertAction alloc] initWithTitle:@"OK" style:PMAlertActionStyleDefault action:^{
	NSString *quittungsVon;
	quittungsVon = [[[quittungDatenAlert textFields] firstObject] text]
	
	(...)
}];

[quittungDatenAlert addAction:alertSend];

[self presentViewController:quittungDatenAlert animated:YES completion:nil];

Instead of accessing the textfield, Xcode now created the following build error:
No visible @interface for 'PMAlertController' declares the selector ‚textFields'

How else could you access the text fields or where is the error?

@pmusolino
Copy link
Owner

Hi there. Sorry for the delay.
What version of PMAlertController are you using?

@Blog404DE
Copy link
Contributor Author

Hi,

that’s no problem :-)
I’ve tested the current version (via pod) and (today) the current master-branch.

During the testing, i’ve seen a second (small) problem in relation with ObjC Projects:
Installing this library via pod (current version) for a objc-project, leads to the following error-message:

pod update                                         
Update all pods
…
Pre-downloading: `PMAlertController` from `https://github.com/pmusolino/PMAlertController.git`, branch `master`
…
Installing PMAlertController 4.0.0
…
[!] Unable to determine Swift version for the following pods:

- `PMAlertController` does not specify a Swift version and none of the targets (`XYZ`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.

A workaround for me was to let the Podfile set the swift-version „by hand“:

pre_install do |installer|
    installer.analysis_result.specifications.each do |s|
        if s.name == 'PMAlertController'
            s.swift_version = '5.0'
        end
    end
end

@pmusolino
Copy link
Owner

I’ll check

@Blog404DE
Copy link
Contributor Author

Hi,

if nearly forgotten this issue - bit now I had some time to look into your swift-code.

The main problem with adding/accessing the textFields from objc code were triggered by two things:

  • The addTextfield hat with one of the last releases a slightly different syntax in objective-c, because you now could (optional) use a custom textField.
[quittungDatenAlert addTextFieldWithTextField:nil :^(UITextField *textField) {
    [textField setPlaceholder: @"Dummy-Placeholder"];
    [textField setKeyboardType:UIKeyboardTypeDefault];
}];
  • Accessing from objective-c code without using a custom textField isn't possible, because textField wasn't declared as accessible. Thats why I've made a small pull-request How to customize like fonts? #95

With this patch, you should be able to use PMAlertController in objective-c projects as in older versions (without major changes in existing codes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants