Method 1: Add [self. textfiled resignfirstresponder] to the button clicking event.
Method 2:
In the XIB file, you can not add a view control on the view page. A simple method is to set the class of the view page to uicontrol (this class inherits from uiview)
. H file:
# Import <uikit/uikit. h> @ interface homeviewcontroller: uiviewcontroller @ property (retain, nonatomic) iboutlet uitextfield * namefield; @ property (retain, nonatomic) iboutlet uitextfield * passwordfield;-(ibaction) textfielddoneediting) sender;-(ibaction) backgroundtap :( ID) sender; @ end
. M file:
# Import "homeviewcontroller. H" @ interface homeviewcontroller () @ end @ implementation homeviewcontroller
@ Synthesize namefield; @ synthesize passwordfield;-(ID) initwithnibname :( nsstring *) nibnameornil bundle :( nsbundle *) handle {self = [Super initwithnibname: nibnameornil Bundle: role] if (Self) {// custom initialization} return self;}-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view from Its nib .} -(void) viewdidunload {[self setnamefield: Nil]; [self setnamefield: Nil]; [self setpasswordfield: Nil]; [Super viewdidunload]; // release any retained subviews of the main view. // e.g. self. myoutlet = nil;}-(bool) returns :( uiinterfaceorientation) interfaceorientation {return (interfaceorientation = inline);}-(void) dealloc {[namefield release]; [namefield release]; [passwordfield release]; [Super dealloc];}-(ibaction) textfielddoneediting :( ID) sender {[Sender resignfirstresponder];}-(ibaction) backgroundtap :( ID) sender {[namefield resignfirstresponder]; [passwordfield resignfirstresponder];} @ end