1

我想做的就是通过子视图中指定的值更改特定 UITableViewCell 中标签的值。我有一个显示产品名称和可用尺寸的 uitableviewcell。在我的应用程序中单击产品单元格后,我会显示包含文本字段的子视图。我使用委托从子视图传递数据,如下面的代码所示。当我返回父视图时,一切正常返回文本字段的值,但我不知道在返回父视图后如何更改特定单元格中标签的值。家长视图.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];

    };

}
4

1 回答 1

0

在 ParentView.m 中尝试:

-(void)viewWillAppear:(BOOL)animated {

  [self.tableView reloadData];
}

如何填写 sizeListLabel?是一个nsarray?要编辑单元格以从 sizeViewController 返回,您应该替换该数组索引处的对象。

于 2013-11-11T15:46:53.253 回答