[ios] Implemented SearchView programmatically for easier localization and faster usage

This commit is contained in:
Alex Zolotarev 2011-11-13 20:04:59 +03:00 committed by Alex Zolotarev
parent 6900c06052
commit 29901b297c
4 changed files with 59 additions and 265 deletions

View file

@ -21,14 +21,13 @@ typedef Framework<model::FeaturesFetcher> framework_t;
framework_t * m_framework;
LocationManager * m_locationManager;
vector<search::Result> m_results;
UISearchBar * m_searchBar;
UITableView * m_table;
// UILabel * m_warningView;
/// Warning view shows only if this text is not nil
// NSString * m_warningViewText;
}
@property (nonatomic, retain) IBOutlet UISearchBar * m_searchBar;
@property (nonatomic, retain) IBOutlet UITableView * m_table;
- (id)initWithFramework:(framework_t *)framework andLocationManager:(LocationManager *)lm;
@end

View file

@ -58,6 +58,23 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
/////////////////////////////////////////////////////////////////////
@interface CustomView : UIView
@end
@implementation CustomView
- (void)layoutSubviews
{
UISearchBar * searchBar = (UISearchBar *)[self.subviews objectAtIndex:0];
[searchBar sizeToFit];
UITableView * table = (UITableView *)[self.subviews objectAtIndex:1];
CGRect rTable;
rTable.origin = CGPointMake(searchBar.frame.origin.x, searchBar.frame.origin.y + searchBar.frame.size.height);
rTable.size = self.bounds.size;
rTable.size.height -= searchBar.bounds.size.height;
table.frame = rTable;
}
@end
////////////////////////////////////////////////////////////////////
/// Key to store settings
#define SEARCH_MODE_SETTING "SearchMode"
#define SEARCH_MODE_POPULARITY "ByPopularity"
@ -67,9 +84,6 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
@implementation SearchVC
@synthesize m_searchBar;
@synthesize m_table;
// Controls visibility of information window with GPS location problems
//- (void)showOrHideGPSWarningIfNeeded
//{
@ -149,7 +163,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
- (id)initWithFramework:(framework_t *)framework andLocationManager:(LocationManager *)lm
{
if ((self = [super initWithNibName:@"Search" bundle:nil]))
if ((self = [super initWithNibName:nil bundle:nil]))
{
m_framework = framework;
m_locationManager = lm;
@ -157,6 +171,30 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
return self;
}
- (void)loadView
{
// create user interface
CustomView * parentView = [[[CustomView alloc] init] autorelease];
parentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
m_searchBar = [[UISearchBar alloc] init];
m_searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
m_searchBar.delegate = self;
m_searchBar.placeholder = @"Search map";
m_searchBar.showsCancelButton = YES;
m_searchBar.showsScopeBar = YES;
m_searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"By popularity", @"On the screen", @"Near me", nil];
[parentView addSubview:m_searchBar];
m_table = [[UITableView alloc] init];
m_table.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
m_table.delegate = self;
m_table.dataSource = self;
[parentView addSubview:m_table];
self.view = parentView;
}
- (void)clearResults
{
m_results.clear();
@ -166,6 +204,8 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
{
// [m_warningViewText release];
g_searchVC = nil;
[m_searchBar release];
[m_table release];
[self clearResults];
[super dealloc];
}
@ -179,8 +219,8 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
{
g_searchVC = nil;
// to correctly free memory
self.m_searchBar = nil;
self.m_table = nil;
[m_searchBar release]; m_searchBar = nil;
[m_table release]; m_table = nil;
m_results.clear();
[super viewDidUnload];
@ -308,18 +348,23 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MyTableViewCell"];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SearchVCTableViewCell"];
if (!cell)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"MyTableViewCell"]
initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SearchVCTableViewCell"]
autorelease];
}
cell.accessoryView = nil;
if (indexPath.row < m_results.size())
{
search::Result const & r = m_results[indexPath.row];
cell.textLabel.text = [NSString stringWithUTF8String:r.GetString()];
[self updateCellDistance:cell withIndex:indexPath.row];
if (r.GetResultType() == search::Result::RESULT_FEATURE)
[self updateCellDistance:cell withIndex:indexPath.row];
else
cell.detailTextLabel.text = nil;
}
else
cell.textLabel.text = @"BUG";
@ -393,8 +438,9 @@ static void OnSearchResultCallback(search::Result const & res, int queryId)
for (NSUInteger i = 0; i < cells.count; ++i)
{
UITableViewCell * cell = (UITableViewCell *)[cells objectAtIndex:i];
[self updateCellAngle:cell withIndex:[m_table indexPathForCell:cell].row
andAngle:((info.m_trueHeading < 0) ? info.m_magneticHeading : info.m_trueHeading)];
NSInteger const index = [m_table indexPathForCell:cell].row;
if (m_results[index].GetResultType() == search::Result::RESULT_FEATURE)
[self updateCellAngle:cell withIndex:index andAngle:((info.m_trueHeading < 0) ? info.m_magneticHeading : info.m_trueHeading)];
}
}
//*********** End of Location manager callbacks ********************

View file

@ -18,7 +18,6 @@
46F26D1F10F626CB00ECCA39 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46F26D1E10F626CB00ECCA39 /* QuartzCore.framework */; };
490830551426B0900088EE84 /* downloader.png in Resources */ = {isa = PBXBuildFile; fileRef = 490830531426B0900088EE84 /* downloader.png */; };
490830561426B0900088EE84 /* downloader@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 490830541426B0900088EE84 /* downloader@2x.png */; };
490830591426BD460088EE84 /* Search.xib in Resources */ = {isa = PBXBuildFile; fileRef = 490830581426BD460088EE84 /* Search.xib */; };
4938BB1D1343652600E0815A /* dictionary.slf in Resources */ = {isa = PBXBuildFile; fileRef = 4938BB1C1343652600E0815A /* dictionary.slf */; };
4945D21C1334187D0082387C /* settings.png in Resources */ = {isa = PBXBuildFile; fileRef = 4945D21A1334187D0082387C /* settings.png */; };
4945D21D1334187D0082387C /* settings@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4945D21B1334187D0082387C /* settings@2x.png */; };
@ -622,7 +621,6 @@
46F8A2EB10EB63040045521A /* MapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = MapViewController.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
490830531426B0900088EE84 /* downloader.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = downloader.png; sourceTree = "<group>"; };
490830541426B0900088EE84 /* downloader@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "downloader@2x.png"; sourceTree = "<group>"; };
490830581426BD460088EE84 /* Search.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Search.xib; sourceTree = SOURCE_ROOT; };
4938BB1C1343652600E0815A /* dictionary.slf */ = {isa = PBXFileReference; lastKnownFileType = file; name = dictionary.slf; path = ../../data/dictionary.slf; sourceTree = "<group>"; };
4945D21A1334187D0082387C /* settings.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = settings.png; sourceTree = "<group>"; };
4945D21B1334187D0082387C /* settings@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "settings@2x.png"; sourceTree = "<group>"; };
@ -1338,7 +1336,6 @@
FA5005611287BFCE002961F0 /* Icon@2x.png */,
28AD73870D9D96C1002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* MapsWithMe-Info.plist */,
490830581426BD460088EE84 /* Search.xib */,
);
name = Resources;
sourceTree = "<group>";
@ -2583,7 +2580,6 @@
FAF805311417E3510024E8C1 /* zw@2x.png in Resources */,
490830551426B0900088EE84 /* downloader.png in Resources */,
490830561426B0900088EE84 /* downloader@2x.png in Resources */,
490830591426BD460088EE84 /* Search.xib in Resources */,
FA459EB414327AF700B5BB3C /* WorldCoasts.mwm in Resources */,
FA85F633145DDDC20090E1A0 /* packed_polygons.bin in Resources */,
);

View file

@ -1,247 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1024</int>
<string key="IBDocument.SystemVersion">11C74</string>
<string key="IBDocument.InterfaceBuilderVersion">1938</string>
<string key="IBDocument.AppKitVersion">1138.23</string>
<string key="IBDocument.HIToolboxVersion">567.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">933</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBUITableView</string>
<string>IBUIView</string>
<string>IBUISearchBar</string>
<string>IBProxyObject</string>
</array>
<array key="IBDocument.PluginDependencies">
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</array>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
<integer value="1" key="NS.object.0"/>
</object>
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<object class="IBProxyObject" id="372490531">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBProxyObject" id="975951072">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="191373211">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUITableView" id="17806054">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">274</int>
<string key="NSFrame">{{0, 88}, {320, 372}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:418</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIAlwaysBounceVertical">YES</bool>
<bool key="IBUIShowsHorizontalScrollIndicator">NO</bool>
<int key="IBUISeparatorStyle">1</int>
<int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
<bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
<float key="IBUIRowHeight">44</float>
<float key="IBUISectionHeaderHeight">22</float>
<float key="IBUISectionFooterHeight">22</float>
</object>
<object class="IBUISearchBar" id="659495066">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">290</int>
<string key="NSFrameSize">{320, 88}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:597</string>
<int key="IBUIContentMode">3</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBPlaceholder">Search maps</string>
<bool key="IBShowsCancelButton">YES</bool>
<object class="IBUITextInputTraits" key="IBTextInputTraits">
<int key="IBUIAutocorrectionType">1</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<array key="IBScopeButtonTitles">
<string>By popularity</string>
<string>On the screen</string>
<string>Near me</string>
</array>
<bool key="IBShowsScopeBar">YES</bool>
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="659495066"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
<object class="NSColorSpace" key="NSCustomColorSpace">
<int key="NSID">2</int>
</object>
</object>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords">
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">m_searchBar</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="659495066"/>
</object>
<int key="connectionID">13</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">view</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="191373211"/>
</object>
<int key="connectionID">14</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">m_table</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="17806054"/>
</object>
<int key="connectionID">16</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="659495066"/>
<reference key="destination" ref="372490531"/>
</object>
<int key="connectionID">12</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="17806054"/>
<reference key="destination" ref="372490531"/>
</object>
<int key="connectionID">17</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">dataSource</string>
<reference key="source" ref="17806054"/>
<reference key="destination" ref="372490531"/>
</object>
<int key="connectionID">18</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
<object class="IBObjectRecord">
<int key="objectID">0</int>
<array key="object" id="0"/>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">1</int>
<reference key="object" ref="191373211"/>
<array class="NSMutableArray" key="children">
<reference ref="659495066"/>
<reference ref="17806054"/>
</array>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="372490531"/>
<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="975951072"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">11</int>
<reference key="object" ref="659495066"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">15</int>
<reference key="object" ref="17806054"/>
<reference key="parent" ref="191373211"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
<string key="-1.CustomClassName">SearchVC</string>
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="11.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="15.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">18</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">SearchVC</string>
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="m_searchBar">UISearchBar</string>
<string key="m_table">UITableView</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="m_searchBar">
<string key="name">m_searchBar</string>
<string key="candidateClassName">UISearchBar</string>
</object>
<object class="IBToOneOutletInfo" key="m_table">
<string key="name">m_table</string>
<string key="candidateClassName">UITableView</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/SearchVC.h</string>
</object>
</object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<real value="1024" key="NS.object.0"/>
</object>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
<real value="4200" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">933</string>
</data>
</archive>