Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (IBAction)doneAdd:(UIBarButtonItem *)sender {
- [self.delegate addItem:[self newItem]];
- }
- - (NSMutableArray *)newItem
- {
- NSMutableArray *newItem = [[NSMutableArray alloc] init];
- for (int i = 0; i < [_appDelegate.title count]; i ++) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
- UPFEditableUITableViewCell *cell = (UPFEditableUITableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
- NSLog(@"%@", cell.editField.text);
- //[newItem addObject:cell.editField.text]; //this does not work as null cannot be added into a array
- }
- NSLog(@"%@", newItem);
- return newItem;
- }
- #import "UPFEditableUITableViewCell.h"
- @implementation UPFEditableUITableViewCell
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.editField = [[UITextField alloc] initWithFrame:CGRectZero];
- [self.contentView addSubview:self.editField];
- }
- return self;
- }
- - (void)layoutSubviews
- {
- if ([self.detailTextLabel.text length] == 0) {
- self.detailTextLabel.text = @" ";
- }
- [super layoutSubviews];
- // place the edit field in the same place as the detail text field, give max width
- self.editField.frame = CGRectMake(self.detailTextLabel.frame.origin.x, self.detailTextLabel.frame.origin.y, self.contentView.frame.size.width-self.detailTextLabel.frame.origin.x, self.detailTextLabel.frame.size.height);
- }
- - (void)showEditingField:(BOOL)show
- {
- self.detailTextLabel.hidden = YES;
- self.editField.text = self.detailTextLabel.text;
- }
- @end
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *cellReuseIdentifier = @"cellIdentifier";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier];
- if (!cell) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier];
- }else{
- NSLog(@"text is %@",cell.textLabel.text);
- for (UIView *v in cell.contentView.subviews) {
- if ([v isKindOfClass:[UITextField class]]) {
- UITextField *textField = (UITextField *)v;
- [myDictionary setObject:textField.text forKey:indexPath]; // declare myDictionary in the interface first.This will also prevent the values from duplicating
- NSLog(@"%@",myDictionary);
- }
- }
- }
- return cell;
- }
- [cell.editField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- cell.editField.delegate = self;
- - (void)textFieldDidChange :(UITextField *)theTextField
- {
- NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
- [self.item removeObjectAtIndex:indexPath.row];
- [self.item insertObject:theTextField.text atIndex:indexPath.row];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement