Единственными объектами, о которых вам нужно позаботиться, будет выделение / освобождение UITextFields.Предполагая, что ваши UITextfields являются ivars (объявленными в вашем заголовочном файле), вы можете использовать следующий код:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect b = [[self view] bounds];
_txt1 = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMidX(b)-100, 50, 200, 29)];
[_txt1 setBorderStyle:UITextBorderStyleRoundedRect];
[[self view] addSubview:_txt1];
_txt2 = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMidX(b)-100, 100, 200, 29)];
[_txt2 setBorderStyle:UITextBorderStyleRoundedRect];
[[self view] addSubview:_txt2];
UIButton* btnSwap = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnSwap setFrame:CGRectMake(CGRectGetMidX(b)-75, 150, 150, 44)];
[btnSwap setTitle:@"Swap Text" forState:UIControlStateNormal];
[btnSwap addTarget:self action:@selector(tappedSwapButton) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:btnSwap];
}
- (void)tappedSwapButton
{
NSString* text1 = [_txt1 text];
NSString* text2 = [_txt2 text];
[_txt2 setText:text1];
[_txt1 setText:text2];
}
- (void)dealloc
{
[_txt1 release];
[_txt2 release];
[super dealloc];
}