pmusolino / PMAlertController

PMAlertController is a great and customizable alert that can substitute UIAlertController
MIT License
2.53k stars 186 forks source link

PMAlertController textfield access via objc #86

Closed Blog404DE closed 4 years ago

Blog404DE commented 5 years ago

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 commented 5 years ago

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

Blog404DE commented 5 years ago

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 commented 5 years ago

I’ll check

Blog404DE commented 4 years ago

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:

[quittungDatenAlert addTextFieldWithTextField:nil :^(UITextField *textField) {
    [textField setPlaceholder: @"Dummy-Placeholder"];
    [textField setKeyboardType:UIKeyboardTypeDefault];
}];

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