从tableviewcell中的textfield中解除键盘

时间:2015-06-04 09:31:27

标签: ios objective-c uitableview keyboard uitextfield

我有一个自定义的tableViewCell,里面有一个文本字段。

如果在文本字段外的任何位置点击键盘时如何解除键盘?

我是否必须使用[cell.textView resignFirstResponder]查看所有单元格?

2 个答案:

答案 0 :(得分:0)

不,你可以使用:

string dst = dataDir + "xml.pdf";
StringBuilder strScenarioXML = new StringBuilder();
strScenarioXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Pdf xmlns=\"Aspose.Pdf\">  <Section PageWidth='612' PageHeight='792' PageMarginTop='5' PageMarginBottom='0.1' PageMarginLeft='30' PageMarginRight='30' IsNewPage='true'>");

strScenarioXML.Append("<Table MarginTop='5' MarginBottom='5' MarginLeft='15' MarginRight='15' DefaultCellPaddingTop='2.0' DefaultCellPaddingRight='2.0' DefaultCellPaddingLeft='2.0' DefaultCellPaddingBottom='2.0' ColumnWidths='100%'><Border><All LineWidth='1'></All></Border>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell><Text Alignment='Left' IsSpaced='false'><Segment  IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='10' >Notes Details</Segment></Text></Cell></Row>");
for (int i = 0; i < 3; i++)
{
    strScenarioXML.Append("<Row><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment  IsUnicode='false' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[comments]]>" + " </Segment>  <Segment></Segment></Text></Cell>");
    strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment  IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[publisher]]>" + "</Segment><Segment></Segment></Text></Cell>");
    strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment  IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[date]]>" + "</Segment><Segment></Segment></Text></Cell></Row>");

}
strScenarioXML.Append("</Table>");
strScenarioXML.Append("</Section></Pdf>");

//Aspose.Words.License licWord = new Aspose.Words.License();
//licWord.SetLicense("Aspose.Words.lic");

//Aspose.Pdf.License lic = new Aspose.Pdf.License();
//lic.SetLicense("Aspose.Custom.lic");

//Aspose.Pdf.License licKit = new Aspose.Pdf.License();
//licKit.SetLicense("Aspose.Custom.lic");



Aspose.Pdf.Generator.Pdf scenarioExportPDF = new Aspose.Pdf.Generator.Pdf();
XmlDocument xmlDoc = new XmlDocument();
//scenarioExportPDF.PageSetup.Margin.Left = 0;
//scenarioExportPDF.PageSetup.Margin.Right = 0;
xmlDoc.LoadXml(strScenarioXML.ToString());
scenarioExportPDF.BindXML(xmlDoc, null);
scenarioExportPDF.Save(dst);
  

endEditing:

     

使视图(或其中一个嵌入的文本字段)重新签署第一个响应者状态。

     

参数:强制

     

指定YES以强制第一响应者辞职,   无论是否愿意这样做。

答案 1 :(得分:0)

试试这段代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  [self.view endEditing:YES];
}

或者您可以添加点击手势识别器:

UITapGestureRecognizer *tapper;

- (void)viewDidLoad
{
    [super viewDidLoad];
    tapper = [[UITapGestureRecognizer alloc]
                initWithTarget:self action:@selector(handleSingleTap:)];
    tapper.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapper];
}

- (void)handleSingleTap:(UITapGestureRecognizer *) sender
{
    [self.view endEditing:YES];
}