root / Classes / RenameServerViewController.m @ 64929bae
History | View | Annotate | Download (2.4 kB)
1 |
// |
---|---|
2 |
// RenameServerViewController.m |
3 |
// OpenStack |
4 |
// |
5 |
// Created by Mike Mayo on 2/9/10. |
6 |
// The OpenStack project is provided under the Apache 2.0 license. |
7 |
// |
8 |
|
9 |
#import "RenameServerViewController.h" |
10 |
#import "RSTextFieldCell.h" |
11 |
#import "UIViewController+Conveniences.h" |
12 |
#import "OpenStackRequest.h" |
13 |
#import "ServerViewController.h" |
14 |
|
15 |
|
16 |
@implementation RenameServerViewController |
17 |
|
18 |
#pragma mark - View lifecycle |
19 |
|
20 |
- (void)viewWillAppear:(BOOL)animated { |
21 |
[super viewWillAppear:animated]; |
22 |
[textField becomeFirstResponder]; |
23 |
} |
24 |
|
25 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { |
26 |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); |
27 |
} |
28 |
|
29 |
#pragma mark - Table view data source |
30 |
|
31 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
32 |
return 1; |
33 |
} |
34 |
|
35 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
36 |
return 1; |
37 |
} |
38 |
|
39 |
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { |
40 |
return @"The name is a tag for identifying your server. You can change it at any time. When rebuilding your server, this name is used as the hostname."; |
41 |
} |
42 |
|
43 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
44 |
static NSString *CellIdentifier = @"RenameCell"; |
45 |
RSTextFieldCell *cell = (RSTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
46 |
if (cell == nil) { |
47 |
cell = [[[RSTextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; |
48 |
cell.modalPresentationStyle = UIModalPresentationFormSheet; |
49 |
textField = cell.textField; |
50 |
textField.delegate = self; |
51 |
} |
52 |
cell.textLabel.text = @"Name"; |
53 |
return cell; |
54 |
} |
55 |
|
56 |
#pragma mark - Button Handlers |
57 |
|
58 |
-(void)saveButtonPressed:(id)sender { |
59 |
if ([textField.text isEqualToString:@""]) { |
60 |
[self alert:@"Error" message:@"Please enter a new server name."]; |
61 |
} else { |
62 |
[self.serverViewController renameServer:textField.text]; |
63 |
[self dismissModalViewControllerAnimated:YES]; |
64 |
[self.serverViewController.tableView deselectRowAtIndexPath:actionIndexPath animated:YES]; |
65 |
} |
66 |
} |
67 |
|
68 |
#pragma mark - Text Field Delegate |
69 |
|
70 |
- (BOOL)textFieldShouldReturn:(UITextField *)textField { |
71 |
[self saveButtonPressed:nil]; |
72 |
return NO; |
73 |
} |
74 |
|
75 |
@end |