Move test fixtures to samples/

This commit is contained in:
Joshua Peek
2012-06-22 10:09:24 -05:00
parent b571c47a1c
commit 5521dd08a0
247 changed files with 13 additions and 14 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
#import <Foundation/Foundation.h>
@interface Foo : NSObject {
}
@end

View File

@@ -0,0 +1,6 @@
#import "Foo.h"
@implementation Foo
@end

View File

@@ -0,0 +1,10 @@
#import <Cocoa/Cocoa.h>
@interface FooAppDelegate : NSObject <NSApplicationDelegate> {
@private
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@end

View File

@@ -0,0 +1,12 @@
#import "FooAppDelegate.h"
@implementation FooAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
@end

View File

@@ -0,0 +1,251 @@
//
// JSONKit.h
// http://github.com/johnezang/JSONKit
// Dual licensed under either the terms of the BSD License, or alternatively
// under the terms of the Apache License, Version 2.0, as specified below.
//
/*
Copyright (c) 2011, John Engelhart
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Zang Industries nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Copyright 2011 John Engelhart
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#include <TargetConditionals.h>
#include <AvailabilityMacros.h>
#ifdef __OBJC__
#import <Foundation/NSArray.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSError.h>
#import <Foundation/NSObjCRuntime.h>
#import <Foundation/NSString.h>
#endif // __OBJC__
#ifdef __cplusplus
extern "C" {
#endif
// For Mac OS X < 10.5.
#ifndef NSINTEGER_DEFINED
#define NSINTEGER_DEFINED
#if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64)
typedef long NSInteger;
typedef unsigned long NSUInteger;
#define NSIntegerMin LONG_MIN
#define NSIntegerMax LONG_MAX
#define NSUIntegerMax ULONG_MAX
#else // defined(__LP64__) || defined(NS_BUILD_32_LIKE_64)
typedef int NSInteger;
typedef unsigned int NSUInteger;
#define NSIntegerMin INT_MIN
#define NSIntegerMax INT_MAX
#define NSUIntegerMax UINT_MAX
#endif // defined(__LP64__) || defined(NS_BUILD_32_LIKE_64)
#endif // NSINTEGER_DEFINED
#ifndef _JSONKIT_H_
#define _JSONKIT_H_
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__APPLE_CC__) && (__APPLE_CC__ >= 5465)
#define JK_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
#else
#define JK_DEPRECATED_ATTRIBUTE
#endif
#define JSONKIT_VERSION_MAJOR 1
#define JSONKIT_VERSION_MINOR 4
typedef NSUInteger JKFlags;
/*
JKParseOptionComments : Allow C style // and /_* ... *_/ (without a _, obviously) comments in JSON.
JKParseOptionUnicodeNewlines : Allow Unicode recommended (?:\r\n|[\n\v\f\r\x85\p{Zl}\p{Zp}]) newlines.
JKParseOptionLooseUnicode : Normally the decoder will stop with an error at any malformed Unicode.
This option allows JSON with malformed Unicode to be parsed without reporting an error.
Any malformed Unicode is replaced with \uFFFD, or "REPLACEMENT CHARACTER".
*/
enum {
JKParseOptionNone = 0,
JKParseOptionStrict = 0,
JKParseOptionComments = (1 << 0),
JKParseOptionUnicodeNewlines = (1 << 1),
JKParseOptionLooseUnicode = (1 << 2),
JKParseOptionPermitTextAfterValidJSON = (1 << 3),
JKParseOptionValidFlags = (JKParseOptionComments | JKParseOptionUnicodeNewlines | JKParseOptionLooseUnicode | JKParseOptionPermitTextAfterValidJSON),
};
typedef JKFlags JKParseOptionFlags;
enum {
JKSerializeOptionNone = 0,
JKSerializeOptionPretty = (1 << 0),
JKSerializeOptionEscapeUnicode = (1 << 1),
JKSerializeOptionEscapeForwardSlashes = (1 << 4),
JKSerializeOptionValidFlags = (JKSerializeOptionPretty | JKSerializeOptionEscapeUnicode | JKSerializeOptionEscapeForwardSlashes),
};
typedef JKFlags JKSerializeOptionFlags;
#ifdef __OBJC__
typedef struct JKParseState JKParseState; // Opaque internal, private type.
// As a general rule of thumb, if you use a method that doesn't accept a JKParseOptionFlags argument, it defaults to JKParseOptionStrict
@interface JSONDecoder : NSObject {
JKParseState *parseState;
}
+ (id)decoder;
+ (id)decoderWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
- (id)initWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
- (void)clearCache;
// The parse... methods were deprecated in v1.4 in favor of the v1.4 objectWith... methods.
- (id)parseUTF8String:(const unsigned char *)string length:(size_t)length JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithUTF8String:length: instead.
- (id)parseUTF8String:(const unsigned char *)string length:(size_t)length error:(NSError **)error JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithUTF8String:length:error: instead.
// The NSData MUST be UTF8 encoded JSON.
- (id)parseJSONData:(NSData *)jsonData JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithData: instead.
- (id)parseJSONData:(NSData *)jsonData error:(NSError **)error JK_DEPRECATED_ATTRIBUTE; // Deprecated in JSONKit v1.4. Use objectWithData:error: instead.
// Methods that return immutable collection objects.
- (id)objectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length;
- (id)objectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length error:(NSError **)error;
// The NSData MUST be UTF8 encoded JSON.
- (id)objectWithData:(NSData *)jsonData;
- (id)objectWithData:(NSData *)jsonData error:(NSError **)error;
// Methods that return mutable collection objects.
- (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length;
- (id)mutableObjectWithUTF8String:(const unsigned char *)string length:(NSUInteger)length error:(NSError **)error;
// The NSData MUST be UTF8 encoded JSON.
- (id)mutableObjectWithData:(NSData *)jsonData;
- (id)mutableObjectWithData:(NSData *)jsonData error:(NSError **)error;
@end
////////////
#pragma mark Deserializing methods
////////////
@interface NSString (JSONKitDeserializing)
- (id)objectFromJSONString;
- (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
- (id)objectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error;
- (id)mutableObjectFromJSONString;
- (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
- (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error;
@end
@interface NSData (JSONKitDeserializing)
// The NSData MUST be UTF8 encoded JSON.
- (id)objectFromJSONData;
- (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
- (id)objectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error;
- (id)mutableObjectFromJSONData;
- (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
- (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError **)error;
@end
////////////
#pragma mark Serializing methods
////////////
@interface NSString (JSONKitSerializing)
// Convenience methods for those that need to serialize the receiving NSString (i.e., instead of having to serialize a NSArray with a single NSString, you can "serialize to JSON" just the NSString).
// Normally, a string that is serialized to JSON has quotation marks surrounding it, which you may or may not want when serializing a single string, and can be controlled with includeQuotes:
// includeQuotes:YES `a "test"...` -> `"a \"test\"..."`
// includeQuotes:NO `a "test"...` -> `a \"test\"...`
- (NSData *)JSONData; // Invokes JSONDataWithOptions:JKSerializeOptionNone includeQuotes:YES
- (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error;
- (NSString *)JSONString; // Invokes JSONStringWithOptions:JKSerializeOptionNone includeQuotes:YES
- (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError **)error;
@end
@interface NSArray (JSONKitSerializing)
- (NSData *)JSONData;
- (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error;
- (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
- (NSString *)JSONString;
- (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error;
- (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
@end
@interface NSDictionary (JSONKitSerializing)
- (NSData *)JSONData;
- (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error;
- (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
- (NSString *)JSONString;
- (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions error:(NSError **)error;
- (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
@end
#ifdef __BLOCKS__
@interface NSArray (JSONKitSerializingBlockAdditions)
- (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error;
- (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error;
@end
@interface NSDictionary (JSONKitSerializingBlockAdditions)
- (NSData *)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error;
- (NSString *)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError **)error;
@end
#endif
#endif // __OBJC__
#endif // _JSONKIT_H_
#ifdef __cplusplus
} // extern "C"
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
@interface MainMenuViewController : TTTableViewController {
}
@end

View File

@@ -0,0 +1,157 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "MainMenuViewController.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation MainMenuViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nil bundle:nil]) {
self.title = @"Style Catalog";
//self.variableHeightRows = YES;
self.tableViewStyle = UITableViewStyleGrouped;
self.dataSource =
[TTSectionedDataSource dataSourceWithObjects:
@"Text Styles",
[TTTableTextItem itemWithText:@"Link Text"
URL:@"tt://styles/linkText:/text"],
[TTTableTextItem itemWithText:@"Mini Badge"
URL:@"tt://styles/miniBadge/text"],
[TTTableTextItem itemWithText:@"Badge"
URL:@"tt://styles/badge/text"],
[TTTableTextItem itemWithText:@"Large Badge"
URL:@"tt://styles/largeBadge/text"],
@"Views",
[TTTableTextItem itemWithText:@"Post Text Editor"
URL:@"tt://styles/postTextEditor/view"],
[TTTableTextItem itemWithText:@"Photo Caption"
URL:@"tt://styles/photoCaption/view"],
[TTTableTextItem itemWithText:@"Photo Status Label"
URL:@"tt://styles/photoStatusLabel/view"],
[TTTableTextItem itemWithText:@"Page Dot"
URL:@"tt://styles/pageDot:/view"],
[TTTableTextItem itemWithText:@"Highlighted Link"
URL:@"tt://styles/linkHighlighted/view"],
[TTTableTextItem itemWithText:@"Table Header"
URL:@"tt://styles/tableHeader/view"],
[TTTableTextItem itemWithText:@"Picker Cell"
URL:@"tt://styles/pickerCell:/view"],
[TTTableTextItem itemWithText:@"Search Table Shadow"
URL:@"tt://styles/searchTableShadow/view"],
[TTTableTextItem itemWithText:@"Black Bezel"
URL:@"tt://styles/blackBezel/view"],
[TTTableTextItem itemWithText:@"White Bezel"
URL:@"tt://styles/whiteBezel/view"],
[TTTableTextItem itemWithText:@"Black Banner"
URL:@"tt://styles/blackBanner/view"],
[TTTableTextItem itemWithText:@"Tab Bar"
URL:@"tt://styles/tabBar/view"],
[TTTableTextItem itemWithText:@"Tab Strip"
URL:@"tt://styles/tabStrip/view"],
@"Tab Grid",
[TTTableTextItem itemWithText:@"Tab Grid"
URL:@"tt://styles/tabGrid/view"],
[TTTableTextItem itemWithText:@"Tab Grid Top Left"
URL:@"tt://styles/tabGridTabTopLeft:/view"],
[TTTableTextItem itemWithText:@"Tab Grid Top Right"
URL:@"tt://styles/tabGridTabTopRight:/view"],
[TTTableTextItem itemWithText:@"Tab Grid Bottom Right"
URL:@"tt://styles/tabGridTabBottomRight:/view"],
[TTTableTextItem itemWithText:@"Tab Grid Bottom Left"
URL:@"tt://styles/tabGridTabBottomLeft:/view"],
[TTTableTextItem itemWithText:@"Tab Grid Left"
URL:@"tt://styles/tabGridTabLeft:/view"],
[TTTableTextItem itemWithText:@"Tab Grid Right"
URL:@"tt://styles/tabGridTabRight:/view"],
[TTTableTextItem itemWithText:@"Tab Grid Center"
URL:@"tt://styles/tabGridTabCenter:/view"],
@"Tabs",
[TTTableTextItem itemWithText:@"Tab"
URL:@"tt://styles/tab:/view"],
[TTTableTextItem itemWithText:@"Round Tab"
URL:@"tt://styles/tabRound:/view"],
[TTTableTextItem itemWithText:@"Tab Left Overflow"
URL:@"tt://styles/tabOverflowLeft/view"],
[TTTableTextItem itemWithText:@"Tab Right Overflow"
URL:@"tt://styles/tabOverflowRight/view"],
@"Images",
[TTTableTextItem itemWithText:@"Thumb View"
URL:@"tt://styles/thumbView:/image"],
@"Launcher",
[TTTableTextItem itemWithText:@"Launcher Button"
URL:@"tt://styles/launcherButton:/image"],
[TTTableTextItem itemWithText:@"Launcher Close Button"
URL:@"tt://styles/launcherCloseButton:/view"],
@"Text Bar",
[TTTableTextItem itemWithText:@"Text Bar"
URL:@"tt://styles/textBar/view"],
[TTTableTextItem itemWithText:@"Text Bar Footer"
URL:@"tt://styles/textBarFooter/view"],
[TTTableTextItem itemWithText:@"Text Bar Text Field"
URL:@"tt://styles/textBarTextField/view"],
[TTTableTextItem itemWithText:@"Text Bar Post Button"
URL:@"tt://styles/textBarPostButton:/text"],
@"Toolbars",
[TTTableTextItem itemWithText:@"Toolbar Button"
URL:@"tt://styles/toolbarButton:/view"],
[TTTableTextItem itemWithText:@"Toolbar Back Button"
URL:@"tt://styles/toolbarBackButton:/view"],
[TTTableTextItem itemWithText:@"Toolbar Forward Button"
URL:@"tt://styles/toolbarForwardButton:/view"],
[TTTableTextItem itemWithText:@"Toolbar Round Button"
URL:@"tt://styles/toolbarRoundButton:/view"],
[TTTableTextItem itemWithText:@"Black Toolbar Button"
URL:@"tt://styles/blackToolbarButton:/view"],
[TTTableTextItem itemWithText:@"Gray Toolbar Button"
URL:@"tt://styles/grayToolbarButton:/view"],
[TTTableTextItem itemWithText:@"Black Toolbar Forward Button"
URL:@"tt://styles/blackToolbarForwardButton:/view"],
[TTTableTextItem itemWithText:@"Black Toolbar Round Button"
URL:@"tt://styles/blackToolbarRoundButton:/view"],
@"Search",
[TTTableTextItem itemWithText:@"Search Text Field"
URL:@"tt://styles/searchTextField/view"],
[TTTableTextItem itemWithText:@"Search Bar"
URL:@"tt://styles/searchBar/view"],
[TTTableTextItem itemWithText:@"Search Bar Bottom"
URL:@"tt://styles/searchBarBottom/view"],
[TTTableTextItem itemWithText:@"Black Search Bar"
URL:@"tt://styles/blackSearchBar/view"],
nil];
}
return self;
}
@end

View File

@@ -0,0 +1,22 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
@interface PlaygroundViewController : UIViewController {
UIScrollView* _scrollView;
}
@end

View File

@@ -0,0 +1,200 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "PlaygroundViewController.h"
#import <Three20Core/NSDataAdditions.h>
static const CGFloat kFramePadding = 10;
static const CGFloat kElementSpacing = 5;
static const CGFloat kGroupSpacing = 10;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation PlaygroundViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
- (CGFloat) addHeader:(NSString*)text yOffset:(CGFloat)yOffset {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = text;
label.font = [UIFont systemFontOfSize:20];
label.numberOfLines = 0;
CGRect frame = label.frame;
frame.origin.x = kFramePadding;
frame.origin.y = yOffset;
frame.size.width = 320 - kFramePadding * 2;
frame.size.height = [text sizeWithFont:label.font
constrainedToSize:CGSizeMake(frame.size.width, 10000)].height;
label.frame = frame;
[_scrollView addSubview:label];
yOffset += label.frame.size.height + kElementSpacing;
TT_RELEASE_SAFELY(label);
return yOffset;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (CGFloat) addText:(NSString*)text yOffset:(CGFloat)yOffset {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = text;
label.numberOfLines = 0;
CGRect frame = label.frame;
frame.origin.x = kFramePadding;
frame.origin.y = yOffset;
frame.size.width = 320 - kFramePadding * 2;
frame.size.height = [text sizeWithFont:label.font
constrainedToSize:CGSizeMake(frame.size.width, 10000)].height;
label.frame = frame;
[_scrollView addSubview:label];
yOffset += label.frame.size.height + kElementSpacing;
TT_RELEASE_SAFELY(label);
return yOffset;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) loadView {
[super loadView];
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
_scrollView.autoresizingMask =
UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_scrollView];
CGFloat yOffset = kFramePadding;
yOffset = [self addHeader:NSLocalizedString(@"TTDebug", @"") yOffset:yOffset];
{
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:NSLocalizedString(@"Debug test", @"") forState:UIControlStateNormal];
[button addTarget: self
action: @selector(debugTestAction)
forControlEvents: UIControlEventTouchUpInside];
[button sizeToFit];
CGRect frame = button.frame;
frame.origin.x = kFramePadding;
frame.origin.y = yOffset;
button.frame = frame;
[_scrollView addSubview:button];
yOffset += frame.size.height;
}
yOffset += kGroupSpacing;
yOffset = [self addHeader:NSLocalizedString(@"TTGlobalCoreLocale", @"") yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"Current locale: %@", @""),
[TTCurrentLocale()
displayNameForKey:NSLocaleIdentifier
value:[TTCurrentLocale() localeIdentifier]]]
yOffset:yOffset];
yOffset += kGroupSpacing;
yOffset = [self addHeader:NSLocalizedString(@"TTGlobalCorePaths", @"") yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"Bundle path: %@", @""),
TTPathForBundleResource(@"Icon.png")]
yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"Document path: %@", @""),
TTPathForDocumentsResource(@"document.pdf")]
yOffset:yOffset];
yOffset += kGroupSpacing;
yOffset = [self addHeader:NSLocalizedString(@"NSDataAdditions", @"") yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"MD5 Hash of \"Three20\": %@", @""),
[[@"Three20" dataUsingEncoding:NSUTF8StringEncoding] md5Hash]]
yOffset:yOffset];
yOffset += kGroupSpacing;
[_scrollView setContentSize:CGSizeMake(320, yOffset)];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) viewDidUnload {
[super viewDidUnload];
TT_RELEASE_SAFELY(_scrollView);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_scrollView flashScrollIndicators];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) debugTestAction {
#ifdef DEBUG
NSLog(@"Three20 debug logging is currently...ON");
#else
NSLog(@"Three20 debug logging is currently...OFF");
#endif
// This will print the current method name.
TTDPRINTMETHODNAME();
TTDPRINT(@"Showing TTDPRINT.");
TTDPRINT(@"-----------------");
TTDPRINT(@"Showing TTD log levels <= %d", TTMAXLOGLEVEL);
TTDERROR(@"This is TTDERROR, level %d.", TTLOGLEVEL_ERROR);
TTDWARNING(@"This is TTDWARNING, level %d.", TTLOGLEVEL_WARNING);
TTDINFO(@"This is TTDINFO, level %d.", TTLOGLEVEL_INFO);
TTDPRINT(@"");
TTDPRINT(@"Showing TTDCONDITIONLOG.");
TTDPRINT(@"------------------------");
TTDCONDITIONLOG(true, @"This will always display because the condition is \"true\"");
TTDCONDITIONLOG(false, @"This will never display because the condition is \"false\"");
TTDCONDITIONLOG(rand()%2, @"This will randomly display because the condition is \"rand()%2\"");
TTDPRINT(@"");
TTDPRINT(@"Showing TTDASSERT.");
TTDPRINT(@"------------------");
// Should do nothing at all.
TTDASSERT(true);
// This will jump you into the debugger in the simulator.
// Note that this isn't a crash! Simply the equivalent of setting
// a breakpoint in the debugger, but programmatically. These TTDASSERTs
// will be completely stripped away from your final product, assuming
// you don't declare the DEBUG preprocessor macro (and you shouldn't in
// your final product).
TTDASSERT(false);
}
@end

View File

@@ -0,0 +1,101 @@
/*
Copyright (C) 2009 Stig Brautaset. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <Foundation/Foundation.h>
/**
@brief Parse JSON Strings and NSData objects
This uses SBJsonStreamParser internally.
@see @ref objc2json
*/
@interface SBJsonParser : NSObject
/**
@brief The maximum recursing depth.
Defaults to 32. If the input is nested deeper than this the input will be deemed to be
malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can
turn off this security feature by setting the maxDepth value to 0.
*/
@property NSUInteger maxDepth;
/**
@brief Description of parse error
This method returns the trace of the last method that failed.
You need to check the return value of the call you're making to figure out
if the call actually failed, before you know call this method.
@return A string describing the error encountered, or nil if no error occured.
*/
@property(copy) NSString *error;
/**
@brief Return the object represented by the given NSData object.
The data *must* be UTF8 encoded.
@param data An NSData containing UTF8 encoded data to parse.
@return The NSArray or NSDictionary represented by the object, or nil if an error occured.
*/
- (id)objectWithData:(NSData*)data;
/**
@brief Return the object represented by the given string
This method converts its input to an NSData object containing UTF8 and calls -objectWithData: with it.
@return The NSArray or NSDictionary represented by the object, or nil if an error occured.
*/
- (id)objectWithString:(NSString *)repr;
/**
@brief Return the object represented by the given string
This method calls objectWithString: internally. If an error occurs, and if @p error
is not nil, it creates an NSError object and returns this through its second argument.
@param jsonText the json string to parse
@param error pointer to an NSError object to populate on error
@return The NSArray or NSDictionary represented by the object, or nil if an error occured.
*/
- (id)objectWithString:(NSString*)jsonText
error:(NSError**)error;
@end

View File

@@ -0,0 +1,100 @@
/*
Copyright (C) 2009,2010 Stig Brautaset. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "SBJsonParser.h"
#import "SBJsonStreamParser.h"
#import "SBJsonStreamParserAdapter.h"
#import "SBJsonStreamParserAccumulator.h"
@implementation SBJsonParser
@synthesize maxDepth;
@synthesize error;
- (id)init {
self = [super init];
if (self)
self.maxDepth = 32u;
return self;
}
#pragma mark Methods
- (id)objectWithData:(NSData *)data {
if (!data) {
self.error = @"Input was 'nil'";
return nil;
}
SBJsonStreamParserAccumulator *accumulator = [[SBJsonStreamParserAccumulator alloc] init];
SBJsonStreamParserAdapter *adapter = [[SBJsonStreamParserAdapter alloc] init];
adapter.delegate = accumulator;
SBJsonStreamParser *parser = [[SBJsonStreamParser alloc] init];
parser.maxDepth = self.maxDepth;
parser.delegate = adapter;
switch ([parser parse:data]) {
case SBJsonStreamParserComplete:
return accumulator.value;
break;
case SBJsonStreamParserWaitingForData:
self.error = @"Unexpected end of input";
break;
case SBJsonStreamParserError:
self.error = parser.error;
break;
}
return nil;
}
- (id)objectWithString:(NSString *)repr {
return [self objectWithData:[repr dataUsingEncoding:NSUTF8StringEncoding]];
}
- (id)objectWithString:(NSString*)repr error:(NSError**)error_ {
id tmp = [self objectWithString:repr];
if (tmp)
return tmp;
if (error_) {
NSDictionary *ui = [NSDictionary dictionaryWithObjectsAndKeys:error, NSLocalizedDescriptionKey, nil];
*error_ = [NSError errorWithDomain:@"org.brautaset.SBJsonParser.ErrorDomain" code:0 userInfo:ui];
}
return nil;
}
@end

View File

@@ -0,0 +1,26 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
@interface StyleViewController : TTViewController {
@private
TTStyle* _style;
TTStyle* _styleHighlight;
TTStyle* _styleDisabled;
TTStyle* _styleSelected;
NSString* _styleType;
}
@end

View File

@@ -0,0 +1,185 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "StyleViewController.h"
#import "StyleView.h"
NSString* kTextStyleType = @"text";
NSString* kViewStyleType = @"view";
NSString* kImageStyleType = @"image";
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation StyleViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithStyleName:(NSString*)name styleType:(NSString*)styleType {
if (self = [super initWithNibName:nil bundle:nil]) {
self.title = name;
_style = [[[TTStyleSheet globalStyleSheet] styleWithSelector:name] retain];
_styleHighlight = [[[TTStyleSheet globalStyleSheet]
styleWithSelector: name
forState: UIControlStateHighlighted] retain];
_styleDisabled = [[[TTStyleSheet globalStyleSheet]
styleWithSelector: name
forState: UIControlStateDisabled] retain];
_styleSelected = [[[TTStyleSheet globalStyleSheet]
styleWithSelector: name
forState: UIControlStateSelected] retain];
_styleType = [styleType copy];
}
return self;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
TT_RELEASE_SAFELY(_style);
TT_RELEASE_SAFELY(_styleHighlight);
TT_RELEASE_SAFELY(_styleDisabled);
TT_RELEASE_SAFELY(_styleSelected);
TT_RELEASE_SAFELY(_styleType);
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UIViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)addTextView:(NSString*)title frame:(CGRect)frame style:(TTStyle*)style {
CGRect textFrame = TTRectInset(frame, UIEdgeInsetsMake(20, 20, 20, 20));
StyleView* text = [[StyleView alloc]
initWithFrame:textFrame];
text.text = title;
TTStyleContext* context = [[TTStyleContext alloc] init];
context.frame = frame;
context.delegate = text;
context.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGSize size = [style addToSize:CGSizeZero context:context];
TT_RELEASE_SAFELY(context);
size.width += 20;
size.height += 20;
textFrame.size = size;
text.frame = textFrame;
text.style = style;
text.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:1 alpha:1];
text.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:text];
TT_RELEASE_SAFELY(text);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)addView:(CGRect)frame style:(TTStyle*)style {
CGRect viewFrame = TTRectInset(frame, UIEdgeInsetsMake(20, 20, 20, 20));
StyleView* view = [[StyleView alloc]
initWithFrame:viewFrame];
view.style = style;
view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:1 alpha:1];
view.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:view];
TT_RELEASE_SAFELY(view);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)addImageView:(CGRect)frame style:(TTStyle*)style {
CGRect viewFrame = TTRectInset(frame, UIEdgeInsetsMake(20, 20, 20, 20));
TTImageView* view = [[TTImageView alloc]
initWithFrame:viewFrame];
view.urlPath = @"bundle://Icon.png";
view.style = style;
view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:1 alpha:1];
view.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
CGRect imageFrame = view.frame;
imageFrame.size = view.image.size;
view.frame = imageFrame;
[self.view addSubview:view];
TT_RELEASE_SAFELY(view);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)loadView {
[super loadView];
CGRect frame = self.view.bounds;
frame.size.height /= 4;
if ([_styleType isEqualToString:kTextStyleType]) {
[self addTextView:@"UIControlStateNormal" frame:frame style:_style];
frame.origin.y += frame.size.height;
[self addTextView:@"UIControlStateHighlighted" frame:frame style:_styleHighlight];
frame.origin.y += frame.size.height;
[self addTextView:@"UIControlStateDisabled" frame:frame style:_styleDisabled];
frame.origin.y += frame.size.height;
[self addTextView:@"UIControlStateSelected" frame:frame style:_styleSelected];
} else if ([_styleType isEqualToString:kViewStyleType]) {
[self addView:frame style:_style];
frame.origin.y += frame.size.height;
[self addView:frame style:_styleHighlight];
frame.origin.y += frame.size.height;
[self addView:frame style:_styleDisabled];
frame.origin.y += frame.size.height;
[self addView:frame style:_styleSelected];
} else if ([_styleType isEqualToString:kImageStyleType]) {
[self addImageView:frame style:_style];
frame.origin.y += frame.size.height;
[self addImageView:frame style:_styleHighlight];
frame.origin.y += frame.size.height;
[self addImageView:frame style:_styleDisabled];
frame.origin.y += frame.size.height;
[self addImageView:frame style:_styleSelected];
}
}
@end

View File

@@ -0,0 +1,217 @@
/*
Copyright 2011 Twitter, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this work except in compliance with the License.
You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import "TUIScrollView.h"
#import "TUIFastIndexPath.h"
typedef enum {
TUITableViewStylePlain, // regular table view
TUITableViewStyleGrouped, // grouped table view—headers stick to the top of the table view and scroll with it
} TUITableViewStyle;
typedef enum {
TUITableViewScrollPositionNone,
TUITableViewScrollPositionTop,
TUITableViewScrollPositionMiddle,
TUITableViewScrollPositionBottom,
TUITableViewScrollPositionToVisible, // currently the only supported arg
} TUITableViewScrollPosition;
typedef enum {
TUITableViewInsertionMethodBeforeIndex = NSOrderedAscending,
TUITableViewInsertionMethodAtIndex = NSOrderedSame,
TUITableViewInsertionMethodAfterIndex = NSOrderedDescending
} TUITableViewInsertionMethod;
@class TUITableViewCell;
@protocol TUITableViewDataSource;
@class TUITableView;
@protocol TUITableViewDelegate<NSObject, TUIScrollViewDelegate>
- (CGFloat)tableView:(TUITableView *)tableView heightForRowAtIndexPath:(TUIFastIndexPath *)indexPath;
@optional
- (void)tableView:(TUITableView *)tableView willDisplayCell:(TUITableViewCell *)cell forRowAtIndexPath:(TUIFastIndexPath *)indexPath; // called after the cell's frame has been set but before it's added as a subview
- (void)tableView:(TUITableView *)tableView didSelectRowAtIndexPath:(TUIFastIndexPath *)indexPath; // happens on left/right mouse down, key up/down
- (void)tableView:(TUITableView *)tableView didDeselectRowAtIndexPath:(TUIFastIndexPath *)indexPath;
- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event; // happens on left/right mouse up (can look at clickCount)
- (BOOL)tableView:(TUITableView*)tableView shouldSelectRowAtIndexPath:(TUIFastIndexPath*)indexPath forEvent:(NSEvent*)event; // YES, if not implemented
- (NSMenu *)tableView:(TUITableView *)tableView menuForRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event;
// the following are good places to update or restore state (such as selection) when the table data reloads
- (void)tableViewWillReloadData:(TUITableView *)tableView;
- (void)tableViewDidReloadData:(TUITableView *)tableView;
// the following is optional for row reordering
- (TUIFastIndexPath *)tableView:(TUITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(TUIFastIndexPath *)fromPath toProposedIndexPath:(TUIFastIndexPath *)proposedPath;
@end
@interface TUITableView : TUIScrollView
{
TUITableViewStyle _style;
__unsafe_unretained id <TUITableViewDataSource> _dataSource; // weak
NSArray * _sectionInfo;
TUIView * _pullDownView;
TUIView * _headerView;
CGSize _lastSize;
CGFloat _contentHeight;
NSMutableIndexSet * _visibleSectionHeaders;
NSMutableDictionary * _visibleItems;
NSMutableDictionary * _reusableTableCells;
TUIFastIndexPath * _selectedIndexPath;
TUIFastIndexPath * _indexPathShouldBeFirstResponder;
NSInteger _futureMakeFirstResponderToken;
TUIFastIndexPath * _keepVisibleIndexPathForReload;
CGFloat _relativeOffsetForReload;
// drag-to-reorder state
TUITableViewCell * _dragToReorderCell;
CGPoint _currentDragToReorderLocation;
CGPoint _currentDragToReorderMouseOffset;
TUIFastIndexPath * _currentDragToReorderIndexPath;
TUITableViewInsertionMethod _currentDragToReorderInsertionMethod;
TUIFastIndexPath * _previousDragToReorderIndexPath;
TUITableViewInsertionMethod _previousDragToReorderInsertionMethod;
struct {
unsigned int animateSelectionChanges:1;
unsigned int forceSaveScrollPosition:1;
unsigned int derepeaterEnabled:1;
unsigned int layoutSubviewsReentrancyGuard:1;
unsigned int didFirstLayout:1;
unsigned int dataSourceNumberOfSectionsInTableView:1;
unsigned int delegateTableViewWillDisplayCellForRowAtIndexPath:1;
unsigned int maintainContentOffsetAfterReload:1;
} _tableFlags;
}
- (id)initWithFrame:(CGRect)frame style:(TUITableViewStyle)style; // must specify style at creation. -initWithFrame: calls this with UITableViewStylePlain
@property (nonatomic,unsafe_unretained) id <TUITableViewDataSource> dataSource;
@property (nonatomic,unsafe_unretained) id <TUITableViewDelegate> delegate;
@property (readwrite, assign) BOOL animateSelectionChanges;
@property (nonatomic, assign) BOOL maintainContentOffsetAfterReload;
- (void)reloadData;
/**
The table view itself has mechanisms for maintaining scroll position. During a live resize the table view should automatically "do the right thing". This method may be useful during a reload if you want to stay in the same spot. Use it instead of -reloadData.
*/
- (void)reloadDataMaintainingVisibleIndexPath:(TUIFastIndexPath *)indexPath relativeOffset:(CGFloat)relativeOffset;
// Forces a re-calculation and re-layout of the table. This is most useful for animating the relayout. It is potentially _more_ expensive than -reloadData since it has to allow for animating.
- (void)reloadLayout;
- (NSInteger)numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
- (CGRect)rectForHeaderOfSection:(NSInteger)section;
- (CGRect)rectForSection:(NSInteger)section;
- (CGRect)rectForRowAtIndexPath:(TUIFastIndexPath *)indexPath;
- (NSIndexSet *)indexesOfSectionsInRect:(CGRect)rect;
- (NSIndexSet *)indexesOfSectionHeadersInRect:(CGRect)rect;
- (TUIFastIndexPath *)indexPathForCell:(TUITableViewCell *)cell; // returns nil if cell is not visible
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect; // returns nil if rect not valid
- (TUIFastIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
- (TUIFastIndexPath *)indexPathForRowAtVerticalOffset:(CGFloat)offset;
- (NSInteger)indexOfSectionWithHeaderAtPoint:(CGPoint)point;
- (NSInteger)indexOfSectionWithHeaderAtVerticalOffset:(CGFloat)offset;
- (void)enumerateIndexPathsUsingBlock:(void (^)(TUIFastIndexPath *indexPath, BOOL *stop))block;
- (void)enumerateIndexPathsWithOptions:(NSEnumerationOptions)options usingBlock:(void (^)(TUIFastIndexPath *indexPath, BOOL *stop))block;
- (void)enumerateIndexPathsFromIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath withOptions:(NSEnumerationOptions)options usingBlock:(void (^)(TUIFastIndexPath *indexPath, BOOL *stop))block;
- (TUIView *)headerViewForSection:(NSInteger)section;
- (TUITableViewCell *)cellForRowAtIndexPath:(TUIFastIndexPath *)indexPath; // returns nil if cell is not visible or index path is out of range
- (NSArray *)visibleCells; // no particular order
- (NSArray *)sortedVisibleCells; // top to bottom
- (NSArray *)indexPathsForVisibleRows;
- (void)scrollToRowAtIndexPath:(TUIFastIndexPath *)indexPath atScrollPosition:(TUITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
- (TUIFastIndexPath *)indexPathForSelectedRow; // return nil or index path representing section and row of selection.
- (TUIFastIndexPath *)indexPathForFirstRow;
- (TUIFastIndexPath *)indexPathForLastRow;
- (void)selectRowAtIndexPath:(TUIFastIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(TUITableViewScrollPosition)scrollPosition;
- (void)deselectRowAtIndexPath:(TUIFastIndexPath *)indexPath animated:(BOOL)animated;
/**
Above the top cell, only visible if you pull down (if you have scroll bouncing enabled)
*/
@property (nonatomic, strong) TUIView *pullDownView;
- (BOOL)pullDownViewIsVisible;
@property (nonatomic, strong) TUIView *headerView;
/**
Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.
*/
- (TUITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;
@end
@protocol TUITableViewDataSource<NSObject>
@required
- (NSInteger)tableView:(TUITableView *)table numberOfRowsInSection:(NSInteger)section;
- (TUITableViewCell *)tableView:(TUITableView *)tableView cellForRowAtIndexPath:(TUIFastIndexPath *)indexPath;
@optional
- (TUIView *)tableView:(TUITableView *)tableView headerViewForSection:(NSInteger)section;
// the following are required to support row reordering
- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(TUIFastIndexPath *)indexPath;
- (void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath;
// the following are required to support row reordering
- (BOOL)tableView:(TUITableView *)tableView canMoveRowAtIndexPath:(TUIFastIndexPath *)indexPath;
- (void)tableView:(TUITableView *)tableView moveRowAtIndexPath:(TUIFastIndexPath *)fromIndexPath toIndexPath:(TUIFastIndexPath *)toIndexPath;
/**
Default is 1 if not implemented
*/
- (NSInteger)numberOfSectionsInTableView:(TUITableView *)tableView;
@end
@interface NSIndexPath (TUITableView)
+ (NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section;
@property(nonatomic,readonly) NSUInteger section;
@property(nonatomic,readonly) NSUInteger row;
@end
#import "TUITableViewCell.h"
#import "TUITableView+Derepeater.h"

File diff suppressed because it is too large Load Diff

View File

View File

@@ -0,0 +1,7 @@
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
NSLog(@"Hello, World!\n");
return 0;
}