这些快速代码意味着什么?

时间:2016-06-13 03:49:22

标签: swift

func textView(textView:UITextView,shouldChangeTextInRange
           rang:NSRange,replacementText text:String)->Bool{
        if(text == "\n"){
            textView.resignFirstResponder()
            return false
        }
        return true
    }

return false && return true)是什么意思?

2 个答案:

答案 0 :(得分:0)

如果某个条件为真,则返回false,否则返回true。你不需要else因为return立即退出函数,返回后的所有代码都不会被执行。

答案 1 :(得分:0)

从函数名Sub Findmergedcellsandfill() Dim MergedCell As Range, Dim FirstAddress As String Dim MergeAddress As String Dim MergeValue As Variant Application.FindFormat.MergeCells = True Do Set MergedCell = ActiveSheet.UsedRange.Find("", LookAt:=xlPart, SearchFormat:=True) If MergedCell Is Nothing Then Exit Do MergeValue = MergedCell.Value MergeAddress = MergedCell.MergeArea.Address MergedCell.MergeArea.UnMerge Range(MergeAddress).Value = MergeValue Loop Application.FindFormat.Clear End Sub 可以清楚地看出它是否应该更改textfield中的字符,因此它会相应地返回一个布尔值...所以如果满足某个条件就像Sub findandfilltheunmergedcells() Dim FolderPath As String Dim WorkBk As Workbook Dim MergedCell As Range, FirstAddress As String, MergeAddress As String, MergeValue As Variant FolderPath = "C:\Users\docs\" FileName = Dir(FolderPath & "*.xl*") Do While FileName <> "" Set WorkBk = Workbooks.Open(FolderPath & FileName) Application.FindFormat.MergeCells = True Do Set MergedCell = ActiveSheet.UsedRange.Find("", LookAt:=xlPart, SearchFormat:=True) If MergedCell Is Nothing Then Exit Do MergeValue = MergedCell.Value MergeAddress = MergedCell.MergeArea.Address MergedCell.MergeArea.UnMerge Range(MergeAddress).Value = MergeValue Loop Application.FindFormat.Clear Loop End Sub 即,如果shouldChangeTextInRange变量的值为text == "\n",它应该重新键入键盘,不应更改字段中的字符。否则,任何键入文本字段的内容都将显示在控件中。