Developer

OpenUI Getting Started (iOS)

This example demonstrates how to set up a simple string display field extension in an Agentry application detailed screen. The string displays in a UI Label and the text has a shadow.

Prerequisites

  • An installed copy of the Agentry Editor that can publish application changes to a server.

  • An installed version of the SAP Mobile Platform Agentry Client framework.

  • You must complete the steps in the OpenUI Overview (iOS) and OpenUI Installation Instructions (iOS) sections before performing these steps.

Step 1: Set up the Field

  1. In your Agentry application, navigate to a screen set that contains a detail screen that contains a string display field. Double click on the field to access the field definition.

  2. Verify the field is targeted to an Object Property and that the Edit Type of the field is set to `String` in the Field Definition tab.

  3. Navigate to the External Field tab, and enter `MyShadowStringDisplayAdapter` in the Class Name attribute.

  4. Save your changes, and publish the modified app to an Agentry Server.

Step 2: Request the View Display

Implement the method that Agentry will call when requesting the view to display for this field. For a view, we will use a UILabel with a shadow. In this case we don't need to retain the view because Agentry will do so for us as long as the screen where the field is displayed exists.

Your code in the .m file should look like this:
#import "MyShadowStringDisplayAdapter.h"
#import <UIKit/UIKit.h>

@interface MyShadowStringDisplayAdapter ()

@property (nonatomic, assign) id<SMPOpenUIStringDisplayModel> model;
@property (nonatomic, retain) UILabel* label;

@end


@implementation MyShadowStringDisplayAdapter

- (id<SMPOpenUIStringDisplayAdapter>)initWithStringDisplayModel:(id<SMPOpenUIStringDisplayModel>)model
{
	if (self = [super init])
	{
		self.model = model;
	}
	return self;
}

- (void)dealloc
{
	self.label = nil;
	[super dealloc];
}

- (UIView *)viewForFrame:(CGRect)frame
{
	self.label = [[[UILabel alloc] initWithFrame:frame] autorelease];

    // So the label always takes up all of the space of the Agentry field
	self.label.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    self.label.shadowColor = [UIColor grayColor];
    self.label.shadowOffset = CGSizeMake(-2.0f , -2.0f);

    // Set the text as it is now
    self.label.text = self.model.value;

	return self.label;
}

@end

Step 3: Send Notification on Text Changes

Implement the method that Agentry will use to notify us of changes to the text displayed by the label (for example, if the field is re-targeted to a different object, or if an update rule is run that produces a different text.

Your code in the .m file should look like this:
#import "MyShadowStringDisplayAdapter.h"
#import <UIKit/UIKit.h>

@interface MyShadowStringDisplayAdapter ()

@property (nonatomic, assign) id<SMPOpenUIStringDisplayModel> model;
@property (nonatomic, retain) UILabel* label;

@end


@implementation MyShadowStringDisplayAdapter

- (id<SMPOpenUIStringDisplayAdapter>)initWithStringDisplayModel:(id<SMPOpenUIStringDisplayModel>)model
{
	if (self = [super init])
	{
		self.model = model;
	}
	return self;
}

- (void)dealloc
{
	self.label = nil;
	[super dealloc];
}

- (UIView *)viewForFrame:(CGRect)frame
{
	self.label = [[[UILabel alloc] initWithFrame:frame] autorelease];

    // So the label always takes up all of the space of the Agentry field
	self.label.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    // This is what makes this string display field special ...
    self.label.shadowColor = [UIColor grayColor];
    self.label.shadowOffset = CGSizeMake(-2.0f , -2.0f);

    // Set the text as it is now
    self.label.text = self.model.value;

	return self.label;
}

- (void)model:(id<SMPOpenUIStringDisplayModel>)model didChangeString:(NSString *)value
{
    // Agentry has modified the text. Make sure we are up to date in the UI as well.
    self.label.text = value;
}

@end

Step 4: Build the Xcode Project

Build and run your Xcode project, and navigate to the same detail screen. The field should now represent your view.

More Examples

For more examples that cover all the adapter and model types and their methods, load the SMPAgentryClientDemo delivered with the framework sample projects in Xcode. More information on that can be found in the OpenUI Installation Instructions (iOS).