Newer
Older
//
// AccountViewController_iPad.m
// ISDS
//
// Created by Petr Hruška on 4/18/11.
// Copyright 2011 CZ.NIC, z.s.p.o. All rights reserved.
//
#import "AccountViewController_iPad.h"
#define ALIAS_INDEX (AUTOALIAS_INDEX + 1)
#define REMOVEBUTTON_OFFSET (30 + 54)
#define CELL_HEIGHT 54
@implementation AccountViewController_iPad
@synthesize autoAliasCell=_autoAliasCell;
@synthesize aliasCell=_aliasCell;
@synthesize aliasTextField=_aliasTextField;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case TEXTFIELDS_SECTION:
return AUTOALIAS_INDEX + 1 + (self.account.useAlias ? 1 : 0);
- (void)setupAliasCell
{
BOOL visible = self.account.useAlias;
[self.autoAliasCell setOn:!visible animated:TRUE];
NSUInteger indexes[2];
indexes[0] = TEXTFIELDS_SECTION;
indexes[1] = ALIAS_INDEX;
NSIndexPath* index = [NSIndexPath indexPathWithIndexes:indexes length:2];
NSArray* aliasRow = [NSArray arrayWithObject:index];
[self.tableView insertRowsAtIndexPaths:aliasRow withRowAnimation:UITableViewRowAnimationTop];
else
[self.tableView deleteRowsAtIndexPaths:aliasRow withRowAnimation:UITableViewRowAnimationTop];
CGRect frame = self.removeButton.frame;
frame.origin.y = self.tableView.frame.origin.y + [self tableView:self.tableView numberOfRowsInSection:TEXTFIELDS_SECTION] * CELL_HEIGHT + REMOVEBUTTON_OFFSET;
[UIView animateWithDuration:0.3 animations:^{ self.removeButton.frame = frame; }];
- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tv deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.section) {
case TEXTFIELDS_SECTION:
switch (indexPath.row) {
case AUTOALIAS_INDEX:
self.account.useAlias = !self.account.useAlias;
[self setupAliasCell];
[super tableView:tv didSelectRowAtIndexPath:indexPath];
}
- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case TEXTFIELDS_SECTION:
switch (indexPath.row) {
case ALIAS_INDEX:
return self.aliasCell;
default:
return [super tableView:tableView_ cellForRowAtIndexPath:indexPath];
}
break;
default:
return [super tableView:tableView_ cellForRowAtIndexPath:indexPath];
}
}
- (void)viewWillAppear:(BOOL)animated {
self.autoAliasCell.on = !self.account.useAlias;
self.aliasTextField.text = self.account.alias;
[super viewWillAppear:animated];
}
- (void)switchCell:(SwitchCell*)cell switchedTo:(BOOL)value
{
if (cell == self.autoAliasCell) {
if (self.account.useAlias != !value) {
self.account.useAlias = !value;
[self setupAliasCell];
}
} else {
[super switchCell:cell switchedTo:value];
}
}
{
}
- (void)viewDidUnload
{
//self.autoAliasCell = nil, it's used to keep state
self.aliasCell = nil;
self.aliasTextField = nil;
}
- (void)dealloc
{
[_autoAliasCell release];
[_aliasCell release];
[_aliasTextField release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
@end