做了一个简单的iphone应用,用于从其他位置复制文本。text1的值到text2。但是运行报出一些警报:
"Attributes on method implementation and its declaration must match"
"Incompatible pointer types sending 'UITextField *' to parameter of type 'NSString *"
两个文本都声明为UITextField。警报出现在setText那行。
#import "APPViewController.h"
@interface APPViewController ()
@end
@implementation APPViewController
-(IBAction)copy:(id)sender
{
[text2 setText:text1];
}
@end
你搞错了,text1是UITextField *, 不是 NSString *。你需要通过发送text消息来获取text1的内容
[text2 setText:[text1 text]];
还可以使用点标记法,像这样:
text2.text = text1.text;