Opening a Terminal to the extracted directory, I then compiled the code:

PowerShell

1

2

3

$cdicu/source

$./runConfigureICU MacOSX

$make&&sudo make install

As I did not have autoconf, I installed it using Brew. Alternatively, you can compile it from source if you do not have Brew.

PowerShell

1

$brew install autoconf

The next few steps are where I had some problems. I was getting strange errors:

fatal error: 'php.h' file not found
and"ERROR: `phpize' failed"

Digging around, it turns out there’s a bit of a strange bug here. It can be quite simply solved by downloading/updating XCode from the App Store and symlinking the XCode SDK headers to the MAMP directory:

In the first part of this tutorial, we set up a pair of simple views in Interface Builder that we switched between modally. In this tutorial, we’ll make them somewhat useful and pass data between them using delegates.

The concept of protocols and delegates is an important and somewhat complex one, but I like to think of it in these simplified terms:

Basically, the object that implements our protocol agrees to implement the methods of that protocol. In the case of this tutorial, we’ll be connecting the modal view with our main view using a delegate.

Firstly, we’ll create the interface elements for our project. Open the ModalViewExampleViewController XIB file and create a button and a label as shown.

Jump to Interface Builder and be sure to link the new elements with the properties we defined. Refer to Part 1 of this tutorial for a guide on how to do that.

The next step is key. We will create a basic protocol and then assign a delegate. Open up ModalViewExampleViewController.h and add this:

Objective-C

1

2

3

4

5

6

// ModalViewExampleViewController.h

@protocolModalViewDelegate

-(void)didReceiveMessage:(NSString*)message;

@end

We then tell ModalViewExampleViewController to implement this protocol:

Objective-C

1

2

// ModalViewExampleViewController.h

@interfaceModalViewExampleViewController: UIViewController

We also need to add the protocol’s method to the main implementation:

Objective-C

1

2

3

4

// ModalViewExampleViewController.m

-(void)didReceiveMessage:(NSString*)message{

}

Once we have these in place, the next step is to set up a reference between the two views. What we will do is define a delegate inside of SampleView so that we can send messages to it.
Include the protocol in ModalViewExampleViewController.h and add the reference:

Objective-C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

// SampleViewController.h

@protocolModalViewDelegate;

@interface SampleViewController : UIViewController{

iddelegate;

UIButton*dismissViewButton;

}

@property(nonatomic,assign)iddelegate;

@property(nonatomic,retain)IBOutletUIButton*dismissViewButton;

-(IBAction)dismissView:(id)sender;

@end

Be sure to synthesize the delegate in SampleViewController.m, and include the necessary header files.

Objective-C

1

2

3

4

5

6

7

8

#import "SampleViewController.h"

#import "ModalViewExampleViewController.h"

@implementationSampleViewController

@synthesizedismissViewButton;

@synthesizedelegate;

...

So far we have defined a protocol inside of our parent view, and defined a delegate in our modal view. The next step is to link them together and make them useful.
Firstly, we’ll write the functions that will handle the messages. Replace the original definition of didReceiveMessage with this:

What we’ve done is create a SampleView object and assigned its delegate to be the parent view. That is, the parent view will be handling messages sent by SampleView.
Open up SampleViewController.m and add the code to send the message.

Objective-C

1

2

3

4

5

6

// SampleViewController.m

-(IBAction)dismissView:(id)sender{

[delegate didReceiveMessage:@"Hello World"];

[self dismissModalViewControllerAnimated:YES];

}

Compile the app and run it. You should be able to see the text “Hello World” passed from one view to another once you dismiss your modal view with delegate. You can extend this any way you like with additional controls on the modal view, such as sliders or text input.