私がしたいのは、サブビューで指定された値で特定の UITableViewCell のラベルの値を変更することだけです。製品名と利用可能なサイズを表示する uitableviewcell があります。アプリケーションで製品セルをクリックすると、テキスト フィールドを含むサブビューが表示されます。以下のコードのように、デリゲートを使用してサブビューからデータを渡します。親ビューに戻ると、すべて問題ありません textfield の値が返されますが、親ビューに戻った後に特定のセルのラベルの値を変更する方法がわかりません。親ビュー.m
-(void)addSizeToParentView:(SizeViewController*)controller didFinishEnteringSizeInfo:(NSString*)sizeInfo{
NSLog(@"This was returned from sizeViewController: %@",sizeInfo);}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"PackageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
UILabel *productNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 300, 29)];
productNameLabel.text = [self.choosedProducts objectAtIndex: indexPath.row];
[cell.contentView addSubview:productNameLabel];
UILabel *sizeListLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 25, 300, 15)];
sizeListLabel.text = @"THIS LABEL SHOULD BE POPULATE BY VALUE OF CHILD VIEW!!"
UIFont *font = [UIFont fontWithName:@"Arial" size:15];
sizeListLabel.font = font;
sizeListLabel.textColor = [UIColor grayColor];
[cell.contentView addSubview:sizeListLabel];
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
SizeViewController *sizeViewController = [storyboard instantiateViewControllerWithIdentifier:@"SizeView"];
sizeViewController.title = [self.choosedProducts objectAtIndex:indexPath.row];
sizeViewController.delegate = self;
[[self navigationController] pushViewController:sizeViewController animated:YES];
}
SizeViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
setSizes = [[NSMutableDictionary alloc]init];
self.tableView.scrollEnabled = NO;
self.manager = [[RETableViewManager alloc] initWithTableView:self.tableView];
self.manager.style.cellHeight = 60;
// Add a section
//
RETableViewSection *section = [RETableViewSection section];
section.headerTitle = @"Specify sizes & quantities";
[self.manager addSection:section];
self.sizes = [RELongTextItem itemWithValue:nil placeholder:@"ex. XL:5, L:10, M:15, S:5, XS:12"];
self.sizes.validators = @[@"presence"];
self.sizes.cellHeight = 200;
[section addItem:self.sizes];
self.sizes.onEndEditing = ^(RELongTextItem *size){
NSLog(@"Value: %@", size.value);
[self.delegate addSizeToParentView:self didFinishEnteringSizeInfo:size.value];
};
}