mardi 4 août 2015

UITextfield value successfully updated, but not shown in table

In my app rows are added to my TableView from a different view. When the user adds the rows the user is taken back to the TableView. The problem is that the text that was previously entered is no longer shown.

I am able to load it with an NSMutableDictionary but the user cannot see it. Any ideas on what I should do? what code I should add and where I should add it? Thanks a lot!

Here is code from a tableview method. I think the fix will go in here somewhere.

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    cell.wtf = [[UITextField alloc]init];

    NSUInteger count =0;
    for (NSMutableDictionary *search in dataForAllRows){ //this just helps me pull the right data out of an array of NSMutableDictionary's

        if ([search valueForKey:@"indexSection"] == [NSNumber numberWithInteger:(indexPath.section -1)]) {

            if ([search valueForKey:@"indexRow"] == [NSNumber numberWithInteger:indexPath.row]) {

                NSMutableDictionary *match = [dataForAllRows objectAtIndex:count];
                [cell.wtf setText:[match objectForKey:@"wtf"]]; 
                NSLog(@"%@",cell.wtf.text); // this outputs the correct value in the command line
            }
        }
        count++;
     }
   }
}

Here is the code for my CustomCell.m

#import "CustomCell.h"

@implementation CustomCell
@synthesize wtf, cellPath;

- (void)awakeFromNib {
// Initialization code

 } 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)layoutSubviews{
wtf = [[UITextField alloc] initWithFrame:CGRectMake(7, 3, 65, self.contentView.bounds.size.height-6)];

self.wtf.delegate = self;

[wtf setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[wtf setAutocorrectionType:UITextAutocorrectionTypeNo];
[wtf setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[wtf setBorderStyle:UITextBorderStyleRoundedRect];
wtf.textAlignment = NSTextAlignmentCenter;
wtf.keyboardType = UIKeyboardTypeNumberPad;  //
[wtf setAutocapitalizationType:UITextAutocapitalizationTypeWords];
[wtf setPlaceholder:@"enter"];

[self.contentView addSubview:wtf];
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire