* Added example with UITableView

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2679 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
loesje_
2013-02-13 20:20:30 +00:00
parent 9729dd4d09
commit 9e192acebc
5 changed files with 486 additions and 0 deletions

View File

@ -0,0 +1,100 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="TableView"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<CustomData Count="7">
<Item0 Name="iPhone/AppID" Value="org.lazarus.tableview"/>
<Item1 Name="iPhone/ExcludeMask"/>
<Item2 Name="iPhone/MainNib" Value="appdelegate_iphoneu"/>
<Item3 Name="iPhone/ResourceDir" Value="Resources"/>
<Item4 Name="iPhone/SDK" Value="5.1"/>
<Item5 Name="iPhone/SimSpaceName" Value="DDE50BDA-0FF1-6929-9C2D-33400B1E2DD3"/>
<Item6 Name="iPhone/isiPhoneApp" Value="true"/>
</CustomData>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="iOSDesigner"/>
</Item1>
<Item2>
<PackageName Value="FCL"/>
</Item2>
</RequiredPackages>
<Units Count="3">
<Unit0>
<Filename Value="TableView.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TableView"/>
</Unit0>
<Unit1>
<Filename Value="appdelegate_iphoneu.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="AppDelegate_iPhone"/>
<HasResources Value="True"/>
<UnitName Value="appdelegate_iphoneu"/>
</Unit1>
<Unit2>
<Filename Value="tabledata.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TableData"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
<CodeGeneration>
<TargetOS Value="iphonesim"/>
</CodeGeneration>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CustomOptions Value="-XR/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk"/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,15 @@
program TableView;
{$modeswitch ObjectiveC1}
uses
iPhoneAll, appdelegate_iphoneu, TableData;
var
pool : NSAutoreleasePool;
begin
pool := NSAutoreleasePool.alloc.init;
UIApplicationMain(argc, argv, nil, nil);
pool.release;
end.

View File

@ -0,0 +1,126 @@
unit appdelegate_iphoneu;
{$modeswitch ObjectiveC1}
interface
uses
Classes,
BufDataset,
iPhoneAll,
SysUtils,
TableData;
type
TTableViewDelegate = objcclass;
{ TAppDelegate_iPhone }
TAppDelegate_iPhone = objcclass(NSObject, UIApplicationDelegateProtocol)
UISearchBar1: UISearchBar;
UITableView1: UITableView;
UIWindow1: UIWindow;
procedure applicationDidFinishLaunching(application: UIApplication); message 'applicationDidFinishLaunching:';
private
objectListTableViewDelegate: TTableViewDelegate;
public
procedure dealloc; override;
end;
{ TTableViewDelegate }
TTableViewDelegate = objcclass(NSObject, UISearchBarDelegateProtocol, UITableViewDataSourceProtocol)
private
FDataStrings: TStrings;
FData: TBufDataset;
FTableView: UITableView;
procedure DatasetToStringlist; message 'DatasetToStringlist';
public
function initWithData(ATableView: UITableView): TTableViewDelegate; message 'initWithData:';
function tableView_numberOfRowsInSection(tableView: UITableView; section: NSInteger): NSInteger; message 'tableView:numberOfRowsInSection:';
function tableView_cellForRowAtIndexPath(tableView: UITableView; indexPath: NSIndexPath): UITableViewCell; message 'tableView:cellForRowAtIndexPath:';
procedure searchBarSearchButtonClicked(searchBar: UISearchBar); message 'searchBarSearchButtonClicked:';
procedure dealloc; override;
end;
implementation
{ TTableViewDelegate }
procedure TTableViewDelegate.DatasetToStringlist;
begin
FDataStrings.Clear;
FData.First;
while not FData.EOF do
begin
FDataStrings.Append(FData.FieldByName('name').asstring);
FData.Next;
end;
end;
function TTableViewDelegate.initWithData(ATableView: UITableView
): TTableViewDelegate;
var
AnAlertView: UIAlertView;
begin
result := init;
FData:= CreateDataset;
FDataStrings := TStringList.Create;
FTableView := ATableView;
DatasetToStringlist;
end;
function TTableViewDelegate.tableView_numberOfRowsInSection(
tableView: UITableView; section: NSInteger): NSInteger;
begin
result := FDataStrings.Count;
end;
function TTableViewDelegate.tableView_cellForRowAtIndexPath(
tableView: UITableView; indexPath: NSIndexPath): UITableViewCell;
var
s: nsstring;
begin
result := tableview.dequeueReusableCellWithIdentifier(NSSTR('DefTableItem'));
if not assigned(result) then
result := UITableViewCell.alloc.initWithStyle_reuseIdentifier(UITableViewStylePlain,NSSTR('DefTableItem'));
s := NSString.alloc.initWithUTF8String(pchar(FDataStrings[indexPath.row]));
result.textLabel.setText(s);
end;
procedure TTableViewDelegate.searchBarSearchButtonClicked(searchBar: UISearchBar);
var
AnAlertView: UIAlertView;
begin
FData.Filter:='name="*'+searchBar.text.cString+'*"';
FData.Filtered:=true;
DatasetToStringlist;
FTableView.reloadData;
end;
procedure TTableViewDelegate.dealloc;
begin
FData.Free;
end;
procedure TAppDelegate_iPhone.applicationDidFinishLaunching(
application: UIApplication);
begin
objectListTableViewDelegate:=TTableViewDelegate.alloc.initWithData(UITableView1);
UITableView1.setDataSource(objectListTableViewDelegate);
UISearchBar1.setDelegate(objectListTableViewDelegate);
end;
procedure TAppDelegate_iPhone.dealloc;
begin
objectListTableViewDelegate.release;
UISearchBar1.release;
UITableView1.release;
UIWindow1.release;
inherited dealloc;
end;
{$FakeResource *.xib}
end.

View File

@ -0,0 +1,201 @@
<?xml version="1.0" encoding="utf-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1280</int>
<string key="IBDocument.SystemVersion">11D50</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.AppKitVersion">1138.32</string>
<string key="IBDocument.HIToolboxVersion">568.00</string>
<object key="IBDocument.PluginVersions" class="NSMutableDictionary">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1181</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBUIWindow</string>
<string>IBUICustomObject</string>
<string>IBUIButton</string>
<string>IBProxyObject</string>
</array>
<array key="IBDocument.PluginDependencies">
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</array>
<object key="IBDocument.Metadata" class="NSMutableDictionary">
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
<integer key="NS.object.0" value="1"/>
</object>
<array id="1000" key="IBDocument.RootObjects" class="NSMutableArray">
<object id="841351856" class="IBProxyObject">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object id="371349661" class="IBProxyObject">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object id="510287021" class="IBUICustomObject"/>
<object id="129156399" class="IBUIWindow">
<string key="NSFrameSize">{320, 480}</string>
<bool key="IBUIOpaque">NO</bool>
<int key="NSvFlags">292</int>
<object key="IBUIBackgroundColor" class="NSColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDE</bytes>
</object>
<object key="IBUISimulatedStatusBarMetrics" class="IBUISimulatedStatusBarMetrics"/>
<bool key="IBUIResizesToFullScreen">YES</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<array key="NSSubviews" class="NSMutableArray">
<object id="291694891" class="IBUITableView">
<reference key="NSSuperview" ref="129156399"/>
<string key="NSFrame">{{0, 64}, {320, 416}}</string>
<int key="NSvFlags">292</int>
<float key="IBUIRowHeight">44</float>
<float key="IBUISectionFooterHeight">22</float>
<float key="IBUISectionHeaderHeight">22</float>
<int key="IBUISeparatorStyle">1</int>
<bool key="IBUIClipsSubviews">YES</bool>
<object key="IBUIBackgroundColor" class="NSColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDE</bytes>
</object>
<bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
<bool key="IBUIAlwaysBounceVertical">YES</bool>
</object>
<object id="527805224" class="IBUISearchBar">
<reference key="NSSuperview" ref="129156399"/>
<string key="NSFrame">{{0, 20}, {320, 44}}</string>
<int key="NSvFlags">292</int>
</object>
</array>
</object>
</array>
<object key="IBDocument.Objects" class="IBObjectContainer">
<array key="connectionRecords" class="NSMutableArray">
<object class="IBConnectionRecord">
<object key="connection" class="IBCocoaTouchOutletConnection">
<reference key="source" ref="841351856"/>
<reference key="destination" ref="510287021"/>
<string key="label">delegate</string>
</object>
<int key="connectionID">3</int>
</object>
<object class="IBConnectionRecord">
<object key="connection" class="IBCocoaTouchOutletConnection">
<reference key="source" ref="510287021"/>
<reference key="destination" ref="129156399"/>
<string key="label">UIWindow1</string>
</object>
<int key="connectionID">5</int>
</object>
<object class="IBConnectionRecord">
<object key="connection" class="IBCocoaTouchOutletConnection">
<reference key="source" ref="510287021"/>
<reference key="destination" ref="291694891"/>
<string key="label">UITableView1</string>
</object>
<int key="connectionID">7</int>
</object>
<object class="IBConnectionRecord">
<object key="connection" class="IBCocoaTouchOutletConnection">
<reference key="source" ref="510287021"/>
<reference key="destination" ref="527805224"/>
<string key="label">UISearchBar1</string>
</object>
<int key="connectionID">9</int>
</object>
</array>
<object key="objectRecords" class="IBMutableOrderedSet">
<array key="orderedObjects">
<object class="IBObjectRecord">
<int key="objectID">0</int>
<array id="0" key="object"/>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="841351856"/>
<reference key="parent" ref="0"/>
<string key="objectName">File's Owner</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">-2</int>
<reference key="object" ref="371349661"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">2</int>
<reference key="object" ref="510287021"/>
<reference key="parent" ref="0"/>
<string key="objectName">AppDelegate_iPhone</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">4</int>
<string key="objectName">UIWindow1</string>
<reference key="object" ref="129156399"/>
<reference key="parent" ref="0"/>
<array key="children" class="NSMutableArray">
<reference ref="291694891"/>
<reference ref="527805224"/>
</array>
</object>
<object class="IBObjectRecord">
<int key="objectID">6</int>
<string key="objectName">UITableView1</string>
<reference key="object" ref="291694891"/>
<reference key="parent" ref="129156399"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">8</int>
<string key="objectName">UISearchBar1</string>
<reference key="object" ref="527805224"/>
<reference key="parent" ref="129156399"/>
</object>
</array>
</object>
<dictionary key="flattenedProperties" class="NSMutableDictionary">
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="2.CustomClassName">TAppDelegate_iPhone</string>
</dictionary>
<dictionary key="unlocalizedProperties" class="NSMutableDictionary"/>
<nil key="activeLocalization"/>
<dictionary key="localizations" class="NSMutableDictionary"/>
<nil key="sourceID"/>
<int key="maxID">13</int>
</object>
<object key="IBDocument.Classes" class="IBClassDescriber">
<object key="referencedPartialClassDescriptions" class="NSMutableArray">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">AppDelegate</string>
<string key="superclassName">NSObject</string>
<object key="outlets" class="NSMutableDictionary">
<string key="NS.key.0">window</string>
<string key="NS.object.0">UIWindow</string>
</object>
<object key="toOneOutletInfosByName" class="NSMutableDictionary">
<string key="NS.key.0">window</string>
<object key="NS.object.0" class="IBToOneOutletInfo">
<string key="name">window</string>
<string key="candidateClassName">UIWindow</string>
</object>
</object>
<object key="sourceIdentifier" class="IBClassDescriptionSource">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/AppDelegate.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object key="IBDocument.PluginDeclaredDevelopmentDependencies" class="NSMutableDictionary">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
<real key="NS.object.0" value="4300"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">1181</string>
</data>
</archive>

View File

@ -0,0 +1,44 @@
unit TableData;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
db,
BufDataset;
function CreateDataset: TBufDataset;
implementation
const
BondArray: array[0..2] of string = (
'Dr. No',
'From Russia with Love',
'Goldfinger'
);
function CreateDataset: TBufDataset;
var
i: Integer;
begin
result := TBufDataset.Create(nil);
result.FieldDefs.Add('ID',ftInteger);
result.FieldDefs.Add('Name',ftString,25);
result.CreateDataset;
result.FilterOptions:=[foCaseInsensitive];
result.Open;
for i := 0 to high(BondArray) do
begin
result.Append;
result.FieldByName('id').AsInteger:=i+1;
result.FieldByName('Name').AsString:=BondArray[i];
end;
result.Post;
end;
end.