Hatena::Groupfukuoka-m

hashimoto.m

 | 

2010-02-09

UITableViewStyleGroupedなUITableViewControllerで設定画面

| 01:33

昨日は、設定画面(作り込み中)だったけど、今日はちょっと進捗があがった。

f:id:m-hashimoto:20100210012435p:image

こんな感じに、アカウントの情報を入力できるようになった。

画面表示時に、ちゃんとフォーカスがURL入力のところにくるようになっている。

いえい。

あと、キーボードのリターンキーも、「Next」だったり「Done」だったりと変化するようにしている。

いえい。

昨日のソースコードから、いじったのは、AddAccountTableViewControllerくらい。

AddAccountTableViewController.h

#import <UIKit/UIKit.h>


@interface AddAccountTableViewController : UITableViewController <UITextFieldDelegate> {
  UITextField *urlField;
  UITextField *accountField;
  UITextField *passwordField;
}

- (id)initWithApplicationDelegate:(id)appDelegate;

@end

「Next」などのキーが動作するよう、UITextFieldDelegateのインタフェースをつけてる。

AddAccountTableViewController.m

#import "AddAccountTableViewController.h"


@implementation AddAccountTableViewController

- (id)initWithApplicationDelegate:(id)appDelegate {
  self = [super initWithStyle:UITableViewStyleGrouped];
  if (self != nil) {
    UIBarButtonItem *save = [[[UIBarButtonItem alloc] initWithTitle:@"Save"
                            style:UIBarButtonItemStylePlain
                           target:appDelegate
                           action:@selector(save)] autorelease];
    self.navigationItem.rightBarButtonItem = save;
    self.title = @"Add Account";
  }
  return self;
}

- (void)viewDidLoad {
  [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  switch (section) {
    case (0):
      return 1;
      break;
    case (1):
      return 2;
      break;
  }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
  NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithFrame:CGRectZero
                     reuseIdentifier:CellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    switch ([indexPath indexAtPosition:0]) {
      case (0):
        switch ([indexPath indexAtPosition:1]) {
          case (0):
            urlField = [[UITextField alloc] initWithFrame:CGRectMake(130.0, 12.0, 200.0, 50.0)];
            [cell addSubview:urlField];
            [urlField setEnabled:YES];
            urlField.returnKeyType = UIReturnKeyNext;
            urlField.text = @"http://";
            urlField.delegate = self;
            cell.textLabel.text = @"URL";
            if ([urlField resignFirstResponder]) {
              [urlField becomeFirstResponder];
            }
            break;
        }
        break;
      case (1):
        switch ([indexPath indexAtPosition:1]) {
          case (0):
            accountField = [[UITextField alloc] initWithFrame:CGRectMake(130.0, 12.0, 200.0, 50.0)];
            [cell addSubview:accountField];
            [accountField setEnabled:YES];
            accountField.returnKeyType = UIReturnKeyNext;
            accountField.delegate = self;
            cell.textLabel.text = @"Account";
            break;
          case (1):
            passwordField = [[UITextField alloc] initWithFrame:CGRectMake(130.0, 12.0, 200.0, 50.0)];
            [cell addSubview:passwordField];
            [passwordField setEnabled:YES];
            [passwordField setSecureTextEntry:YES];
            passwordField.returnKeyType = UIReturnKeyDone;
            cell.textLabel.text = @"Password";
            break;
        }
        break;
    }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

- (void)dealloc {
  [urlField release];
  [accountField release];
  [passwordField release];
  [super dealloc];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  if (textField == urlField) {
    [accountField becomeFirstResponder];
  } else if (textField == accountField) {
    [passwordField becomeFirstResponder];
  }
}

@end

ひとまず、こんな感じ。

TableViewControllerと、フィールド群を別クラスに分けようかな・・・とか思うも、まぁ、いいかと、置いておく。

次は、「Save」もしくはパスワード入力後の「Done」キーで、WordPressログインできるかどうかを確認する部分を作ろうかと思う。

ちなみに、マルチアカウント対応のつもり。

PokeyPokey2012/01/14 06:42I'll try to put this to good use imedmiatley.

mmeozwkmcgommeozwkmcgo2012/01/14 17:24EXiBaY <a href="http://maobohqvxjyx.com/">maobohqvxjyx</a>

wlfisclowlfisclo2012/01/16 18:438Qp12F <a href="http://vkurkilcsltu.com/">vkurkilcsltu</a>

 |