简体   繁体   中英

How to update custom specific UITableview cell in storyboard, which are dynamically generated?

I am developing my first app in objective-c. In first view controller I am able to generate UITableview with dynamic prototype cells containing accessory button. When I click on the accessory button, it will navigate to next view controller, which would also having dynamic UITableviewcells with (Custom button)Select as accessory button. But, when I click on the specific select button, corresponding cell contents should be updated in the cell(In first screen) for which accessory button is clicked. I am able to get the details from the second screen to first screen. But, my custom cell in the first screen is not updating?

Please help whether there is any pre-defined function, which I've not found in the reference doc.

Thankyou in advance..

There is a solution algoritm come from beginning ios 5 development.

1.Take the indexPath in prepareSegue

// prepare selection info
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];

2.Send that to second view controller

    UIViewController *destination = segue.destinationViewController;
    [destination setValue:self forKey:@"delegate"];

    id object = [self.tasks objectAtIndex:indexPath.row];
    NSDictionary *selection = [NSDictionary dictionaryWithObjectsAndKeys:indexPath,@"indexPath",object,@"object", nil];        
    [destination setValue:selection forKey:@"selection"];

3.The second view controller later will send back the indexPath to the first controller

// prepare selection info back
NSIndexPath *indexPath = [_selection objectForKey:@"indexPath"];
id object = _textView.text;
NSDictionary *editedSelection = [NSDictionary dictionaryWithObjectsAndKeys:indexPath, @"indexPath", object, @"object", nil];
[_delegate setValue:editedSelection forKey:@"editedSelection"];

4.So in the getter method of first view controller which used to take the indexPath back from the secomd view controller, you take back the table cell by indexPath and change its value

#pragma mark - Call back by destination view
-(void)setEditedSelection:(NSDictionary *)dict{
    NSIndexPath *indexPath = [dict objectForKey:@"indexPath"];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    ....
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM