如何通过子视图ios返回的值更改字幕单元格的值

时间:2013-11-11 15:43:29

标签: ios objective-c uitableview

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

    };

}

1 个答案:

答案 0 :(得分:0)

在ParentView.m中尝试:

-(void)viewWillAppear:(BOOL)animated {

  [self.tableView reloadData];
}

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