Hi ayush did u get the solution on this.....
Hi phoneydeveloper
Please suggest some better idea on following issue...
I have added a textfield in the cell (not created customcell)and fetched the values from the textfield while editing the record...
but the problem is
1) the textfield is not getting deallocated even if i release the textfield memory as the cell retains the instance of textfield.....
2) and also due to tableview property it creates the cell when cell is visible so continues alloction of textfield is their..
3)I am inserting & deleting cell ( UITableViewCellEditingStyle).. so if i delete the cell the cell gets deallocated & the textfield vanishes but it is still their in the view(doesn't gets deallocated)
Their is no crash while executing this code (following code is edited)
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
CGRect bounds = [cell.contentView bounds];
CGRect rect = CGRectInset(bounds, 20.0, 10.0);
switch (indexPath.section) {
case DContactSection:
NSLog(@"Conatcats child phone....");
if ([arryCPerson count] > 0) {
NSString *tag = [NSString stringWithFormat:@"%d%d%d",DContactSection+1,indexPath.row+1,3];
int _tag = [tag intValue];
NSString *_email = [[arryCPerson objectAtIndex:indexPath.row] objectForKey:@"scfname"];
UITextField *txt = [self setTextField:rect setTag:_tag];
txt.text = _email;
txt.placeholder=@"ContactPerson";
[cell.contentView addSubview:txt];
}
break;
case DCallSection:{
NSString *tag = [NSString stringWithFormat:@"%d%d%d",DCallSection+1,indexPath.row+1,3];
int _tag = [tag intValue];
UITextField *txt = [self setTextField:rect setTag:_tag];
txt.text = [mutdict objectForKey:@"tollfree"];
txt.placeholder=@"Tollfree";
[cell.contentView addSubview:txt];
break;
}
}
return cell;
}
-(UITextField*)setTextField:(CGRect)rect setTag:(int)_tag{
UITextField *txtcell = [[[UITextField alloc] init]autorelease];
rect.size.width=240;
txtcell.frame = rect;
txtcell.tag = _tag;
[txtcell setReturnKeyType:UIReturnKeyNext];
[txtcell setDelegate:self];
[txtcell setBackgroundColor:[UIColor whiteColor]];
[txtcell setOpaque:YES];
return txtcell;
}
Also i have saved the textfield value on - (void)textFieldDidEndEditing
UITextField *)textField.....
but if i am on last textfield and do not move the cursor to other textfield and click the save button on navigation bar the above function is not called thus doesn't saves the last textfield value
Code:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *_tag = [NSString stringWithFormat:@"%d",[textField tag]];
NSRange range = NSMakeRange(0,1);
NSString *_sec = [_tag substringWithRange:range];
range = NSMakeRange(1,1);
NSString *_row = [_tag substringWithRange:range];
int sec =[_sec intValue]-1;
int row =[_row intValue]-1;
NSLog(@"sec= %d row=%d",sec,row);
NSLog(@"Textfield=%@",textField.text);
if (sec==DContactSection) {
[[arryCPerson objectAtIndex:row] setValue:textField.text forKey:@"scfname"];
}
if (sec==DCallSection) {
[mutdict setValue:textField.text forKey:@"tollfree"];
}
}