###前提・実現したいこと
1、UIAlertControllerでYESをタップした時にTableview上に配置したTextfieldへ値を入れたいのですが実装方法が分かりません。(同時にdelegateにも値を保存させたいです。)
2、下記コードは2頁目なのですが、1頁目へ戻る方法もご教授いただけると幸いです。
###該当のソースコード
#import "CalcViewController.h"
#import "SettingViewController.h"
#import "CalcAppDelegate.h"
@implementation SettingViewController
@synthesize settinglist;
@synthesize ATextDelegate;
@synthesize BTextDelegate;
@synthesize CTextDelegate;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
CalcAppDelegate calcAppDelegate;
calcAppDelegate = (CalcAppDelegate)[[UIApplication sharedApplication] delegate];
CalcView = calcAppDelegate.setting00;
settinglist = [[NSMutableArray alloc] initWithObjects:
@"AText",
@"BText",
@"CText",
@"Change",
nil];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger count = [settinglist count];
return count;
}
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 80.0;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
tableView.scrollEnabled = false;
if (indexPath.row == 0) {
UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(150.0f, 25.0f, 70.0f, 28.0f)];
textField1.text = @"123";
textField1.borderStyle = UITextBorderStyleRoundedRect;
textField1.delegate = self;
[cell.contentView addSubview:textField1];
} else if (indexPath.row == 1) {
UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(150.0f, 25.0f, 70.0f, 28.0f)];
textField2.text = @"456";
textField2.borderStyle = UITextBorderStyleRoundedRect;
textField2.delegate = self;
[cell.contentView addSubview:textField2];
} else if (indexPath.row == 2) {
UITextField *textField3 = [[UITextField alloc] initWithFrame:CGRectMake(150.0f, 25.0f, 70.0f, 28.0f)];
textField3.text = @"789";
textField3.borderStyle = UITextBorderStyleRoundedRect;
textField3.delegate = self;
[cell.contentView addSubview:textField3];
} else if (indexPath.row == 3) {
UIButton *settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
settingButton.frame = CGRectMake(210.0f, 300.0f, 100.0f, 30.0f);
[settingButton setTitle:@"Change", forState:UIControlStateNormal];
[settingButton addTarget:self action:@selector(tapButton:) forControlEvents:UIControlEventTouchUpInside];
[settingButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[self.view addSubview:settingButton];
}
}
cell.textLabel.text = [settinglist objectAtIndex:indexPath.row];
return cell;
nil];
}
-(void)tapButton:(id)sender {
NSLog(@"Riset Button tapped.");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Check" message:@"Change?" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self otherButtonPushed];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self cancelButtonPushed];
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
-
(void)cancelButtonPushed { }
-
(void)otherButtonPushed {
// ここで下記のようにしたいです。同時にDelegateにも代入させたいです。
// textField1 = @"321";
// textField2 = @"654";
// textField3 = @"987";
}
###補足情報
Xcode Version7.3.1
初心者なので必要な情報が足りていないかもしれませんがご教授のほど宜しくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/13 00:40