Statistics
| Branch: | Revision:

root / asi-http-request-with-pithos / iPhone Sample / SampleViewController.m @ be116d22

History | View | Annotate | Download (2.7 kB)

1
//
2
//  SampleViewController.m
3
//  Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4
//
5
//  Created by Ben Copsey on 17/06/2010.
6
//  Copyright 2010 All-Seeing Interactive. All rights reserved.
7
//
8

    
9
#import "SampleViewController.h"
10

    
11
// Private stuff
12
@interface SampleViewController ()
13
- (void)keyboardWillShow:(NSNotification *)notification;
14
- (void)keyboardWillHide:(NSNotification *)notification;
15
@end
16

    
17

    
18

    
19
@implementation SampleViewController
20

    
21
- (void)showNavigationButton:(UIBarButtonItem *)button
22
{
23
    [[[self navigationBar] topItem] setLeftBarButtonItem:button animated:NO];	
24
}
25

    
26
- (void)hideNavigationButton:(UIBarButtonItem *)button
27
{
28
    [[[self navigationBar] topItem] setLeftBarButtonItem:nil animated:NO];
29
}
30

    
31
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
32
{
33
	return YES;
34
}
35

    
36
- (NSIndexPath *)tableView:(UITableView *)theTableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
37
{
38
	return nil;
39
}
40

    
41
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
42
{
43
	[[self tableView] reloadData];
44
}
45

    
46
- (void)viewDidLoad
47
{
48
	[[self view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
49
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
50
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
51
}
52

    
53
- (void)viewDidUnload {
54
    [super viewDidUnload];
55
    [self setNavigationBar:nil];
56
	[self setTableView:nil];
57
}
58

    
59
- (void)keyboardWillShow:(NSNotification *)notification
60
{
61
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
62
	NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
63
#else
64
	NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
65
#endif
66
	CGRect keyboardBounds;
67
	[keyboardBoundsValue getValue:&keyboardBounds];
68
	UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height-42, 0);
69
	[[self tableView] setScrollIndicatorInsets:e];
70
	[[self tableView] setContentInset:e];
71
}
72

    
73
- (void)keyboardWillHide:(NSNotification *)notification
74
{
75
	UIEdgeInsets e = UIEdgeInsetsMake(0, 0, 0, 0);
76
	[[self tableView] setScrollIndicatorInsets:e];
77
	[[self tableView] setContentInset:e];	
78
}
79

    
80
- (void)dealloc {
81
	[navigationBar release];
82
	[tableView release];
83
	[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
84
	[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
85
    [super dealloc];
86
}
87

    
88
@synthesize navigationBar;
89
@synthesize tableView;
90
@end