Skip to content

Commit

Permalink
Updated States Examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
probablycorey committed Jan 3, 2011
1 parent 3ecf133 commit 37cbea3
Show file tree
Hide file tree
Showing 16 changed files with 1,527 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/States (without wax.framework)/Classes/ProtocolLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Many protocols will work from wax out of the box. But some need to be preloaded.
// If the protocol you are using isn't found, just add the protocol to this object
//
// This seems to be a bug, or there is a runtime method I'm unaware of

#import <UIKit/UIKit.h>

@interface ProtocolLoader : NSObject <UIApplicationDelegate, UIWebViewDelegate, UIActionSheetDelegate, UIAlertViewDelegate, UISearchBarDelegate, UITextViewDelegate, UITabBarControllerDelegate> {}
@end

@implementation ProtocolLoader
@end
8 changes: 8 additions & 0 deletions examples/States (without wax.framework)/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>get-task-allow</key>
<false/>
</dict>
</plist>
Binary file added examples/States (without wax.framework)/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/States (without wax.framework)/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "wax/lib/project.rake"
30 changes: 30 additions & 0 deletions examples/States (without wax.framework)/States-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleDocumentTypes</key>
<array/>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>Icon.png</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
</dict>
</plist>

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions examples/States (without wax.framework)/States_Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'States' target in the 'States' project
//

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
27 changes: 27 additions & 0 deletions examples/States (without wax.framework)/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// main.m
// States
//
// Created by Corey on 1/3/11.
// Copyright me 2011. All rights reserved.
//
// This where the magic happens!
// Wax doesn't use nibs to load the main view, everything is done within the
// AppDelegate.lua file

#import <UIKit/UIKit.h>

#import "wax.h"
#import "wax_http.h"
#import "wax_json.h"
#import "wax_xml.h"

int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

wax_start("AppDelegate", luaopen_wax_http, luaopen_wax_json, luaopen_wax_xml, nil);

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
[pool release];
return retVal;
}
17 changes: 17 additions & 0 deletions examples/States (without wax.framework)/scripts/AppDelegate.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "StatesTable"
require "CapitalsTable"

waxClass{"AppDelegate", protocols = {"UIApplicationDelegate"}}

function applicationDidFinishLaunching(self, application)
local frame = UIScreen:mainScreen():bounds()
self.window = UIWindow:initWithFrame(frame)
self.window:setBackgroundColor(UIColor:orangeColor())
self.window:makeKeyAndVisible()

local statesTable = StatesTable:init()
self.navigationController = UINavigationController:initWithRootViewController(statesTable)

self.window:addSubview(self.navigationController:view())
end

36 changes: 36 additions & 0 deletions examples/States (without wax.framework)/scripts/CapitalsTable.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
waxClass{"CapitalsTable", UITableViewController, protocols = {"UITableViewDataSource"}}

function init(self, state)
self.super:initWithStyle(UITableViewStyleGrouped)
self.state = state
self:setTitle(state.name)
return self
end


function viewDidLoad(self)
self:tableView():setDataSource(self)
end

-- DataSource
-------------
function numberOfSectionsInTableView(self, tableView)
return 1
end

function tableView_numberOfRowsInSection(self, tableView, section)
return #table.keys(self.state)
end

function tableView_cellForRowAtIndexPath(self, tableView, indexPath)
local identifier = "CapitalsTableCell"
local cell = tableView:dequeueReusableCellWithIdentifier(identifier) or
UITableViewCell:initWithStyle_reuseIdentifier(UITableViewCellStyleValue1, identifier)

local key = table.keys(self.state)[indexPath:row() + 1]
cell:detailTextLabel():setText(tostring(self.state[key]))
cell:textLabel():setText(key)
cell:setSelectionStyle(UITableViewCellSelectionStyleNone)

return cell
end
50 changes: 50 additions & 0 deletions examples/States (without wax.framework)/scripts/StatesTable.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@


waxClass{"StatesTable", UITableViewController, protocols = {"UITableViewDataSource", "UITableViewDelegate"}}

function init(self)
self.super:init()

-- Loads plist from bundle
self.states = NSArray:arrayWithContentsOfFile("states.plist")

self:setTitle("States")
return self
end

function viewDidLoad(self)
self:tableView():setDataSource(self)
self:tableView():setDelegate(self)
end

-- DataSource
-------------
function numberOfSectionsInTableView(self, tableView)
return 1
end

function tableView_numberOfRowsInSection(self, tableView, section)
return #self.states
end

function tableView_cellForRowAtIndexPath(self, tableView, indexPath)
local identifier = "StateCell"
local cell = tableView:dequeueReusableCellWithIdentifier(identifier) or
UITableViewCell:initWithStyle_reuseIdentifier(UITableViewCellStyleDefault, identifier)

local state = self.states[indexPath:row() + 1]
cell:textLabel():setText(state["name"]) -- Must +1 because lua arrays are 1 based
cell:setAccessoryType(UITableViewCellAccessoryDisclosureIndicator)

return cell
end

-- Delegate
-----------
function tableView_didSelectRowAtIndexPath(self, tableView, indexPath)
self:tableView():deselectRowAtIndexPath_animated(indexPath, true)
local state = self.states[indexPath:row() + 1]

local viewController = CapitalsTable:init(state)
self:navigationController():pushViewController_animated(viewController, true)
end
Loading

0 comments on commit 37cbea3

Please sign in to comment.