Iphone UITableView中的文本字段
我对iphone还不熟悉。。。正在尝试此代码,但遇到一些错误,请帮助我Iphone UITableView中的文本字段,iphone,cocoa-touch,Iphone,Cocoa Touch,我对iphone还不熟悉。。。正在尝试此代码,但遇到一些错误,请帮助我 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ ........//// some code ...........////////// CGRect frame = CGRectMake(5 ,10 , 320, 44); UITextFie
- (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 ////////////
我使用此代码在tableview中显示textfield,然后从textfield中访问值。b但是获取“saveChange”方法“UITextField*name=(UITextField*)[self.viewWithTag:1]”中的错误:-视图不是结构或联合。
请告诉我,您的文本字段不是ViewController类视图的子视图(您在其中引用“self”)。它位于特定的
UITAbleViewCell
中。因此,您必须确定要从哪个表单元格中获取textview内容,并将其从单元格的contentview中取出
此外,您可以在将来省去一些麻烦,并在请求时检查是否返回了视图,例如:
UIView *aView = [someView viewWithTag:1];
if( aView != nil ){
...
}else{
...
}
您的文本字段不是ViewController类视图的子视图(您在其中引用“self”)。它位于特定的
UITAbleViewCell
中。因此,您必须确定要从哪个表单元格中获取textview内容,并将其从单元格的contentview中取出
此外,您可以在将来省去一些麻烦,并在请求时检查是否返回了视图,例如:
UIView *aView = [someView viewWithTag:1];
if( aView != nil ){
...
}else{
...
}
不知道这是问题还是代码中的输入错误:
[self.viewWithTag:1]
但是你不应该在里面有一个点:
[self viewWithTag:1]
不知道这是问题还是代码中的输入错误:
[self.viewWithTag:1]
但是你不应该在里面有一个点:
[self viewWithTag:1]
保存方法的代码应为:
-(IBAction ) saveChanges:(id) sender
{
UITextField *name =(UITextField *)[self.view viewWithTag:1];
UITextField *bday= (UITextField *)[self.view viewWithTag:2];
UITextField *note=(UITextField *)[self.view viewWithTag:3];
//// some code ////////////
}
您正在访问与放置此代码的控制器相关的视图的标记子视图。保存方法的代码应为:
-(IBAction ) saveChanges:(id) sender
{
UITextField *name =(UITextField *)[self.view viewWithTag:1];
UITextField *bday= (UITextField *)[self.view viewWithTag:2];
UITextField *note=(UITextField *)[self.view viewWithTag:3];
//// some code ////////////
}
您正在访问与放置此代码的控制器相关的视图的标记子视图