i m new to iphone … trying this code but getting some error help me out..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
........//// some code ...........//////////
CGRect frame = CGRectMake(5 ,10 , 320, 44);
UITextField *txtField = [[UITextField alloc]initWithFrame:frame];
[txtField setBorderStyle:UITextBorderStyleNone];
txtField.delegate=self;
switch (indexPath.row) {
case 0:
txtField.placeholder=editFrndBDb.frndName;
txtField.text=editFrndBDb.frndName;
txtField.tag=1;
break;
case 1:
txtField.placeholder=editFrndBDb.bDay;
txtField.text=editFrndBDb.bDay;
txtField.tag=2;
break;
case 2:
txtField.placeholder=editFrndBDb.frndNote;
txtField.text=editFrndBDb.frndNote;
txtField.tag=3;
break;
default:
break;
}
[cell.contentView addSubview:txtField];
[txtField release];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
return cell;
}
-(IBAction ) saveChanges:(id) sender
{
UITextField *name =(UITextField *)[self.viewWithTag:1];
UITextField *bday= (UITextField *)[self.viewWithTag:2];
UITextField *note=(UITextField *)[self.viewWithTag:3];
//// some code ////////////
i m using this code to display textfield in tableview and then access the value from the textfield. Bbut getting the error in the “saveChange” method “UITextField *name =(UITextField *)[self.viewWithTag:1]” error :- view is something not a structure or a union.
plz me out of this
Your textfield is not a subview of the ViewController class’s view (where you reference “self”). It’s inside a particular
UITAbleViewCell. So you’ll have to figure out which table cell you want the textview contents from and get it out of the cell’s contentview.Moreover, you could save some trouble in the future and check that you get a view returned when asking for it, e.g.: