Objective-C if-else 语句

发布于 2024-12-27 11:55:10 字数 1202 浏览 5 评论 0原文

在我看来,我有一个 UITextLabel 和一个 UITextView 占据相同的空间。我分配了一个 NSMutableArray 来根据用户在表格中点击的内容填充 UITextLabel 。我还想对应用程序进行编程,以使用 UITextView 当且仅当用户点击一个特定行。我认为这可以通过 if-else (if) 语句来完成,但我不确定。如果这行得通,我不知道在 if 部分要放什么。到目前为止,我有这样的情况:

if (qux == ??) {

    fooTextView.text = textString;

} else {

    fooTextLabel.text = textString;

}

我不知道如何设置 if 语句。我尝试将其设置为

if (qux == 包含单个数组语句的非常长的代码 我想显示为 UITextView)

但返回了错误。有人建议如何让 Xcode 使用 UITextView 识别我的单个 NSMutableArray 表格单元格,而不是(也)使用 UILabel 识别我的单个 NSMutableArray 表格单元格吗?截至目前,应用程序已构建,但在 UITextView 中显示文本,因此它可以滚动并完全按照我想要的方式执行操作,但也显示在 UILabel 中,并且是静态的在滚动 UITextView 的“下方”可见。

另外,我将 NSMutable 数组与 initWithObjectAndKeys 一起使用。在这种特殊情况下,这是我的 UITableView 中唯一的此类情况,我使用了一个仅由数组的该特定部分使用的特殊键。是否可以将其设置为以下内容:

if (qux == *NSMutableArray with the special key*) {

    fooTextView.text = textString;

} else {

    fooTextLabel.text = textString;

}

我应该使用 if-else if 语句还是仅使用 if-else 语句?

I have both a UITextLabel and a UITextView occupying the same real estate, point-for-point in my view. I have an NSMutableArray allocated to populate the UITextLabel based on what the user taps in a table. I would also like to program the app to use the UITextView if and only if the user taps on one specific row. I think this can be accomplished with an if-else (if) statement, but I'm not sure. If that will work, I don't know what to put in the if part. So far, I have this:

if (qux == ??) {

    fooTextView.text = textString;

} else {

    fooTextLabel.text = textString;

}

I don't know what to set the if statement to. I tried to set it to

if (qux == the really long code containing the single array statement
I want displayed as a UITextView
)

but that returned an error. Does anyone have a suggestion on how to get Xcode to recognize my single NSMutableArray table cell with the UITextView and not (also) with the UILabel? As of right now, the app builds but displays the text both in the UITextView, so it scrolls and does exactly what I want but also displays in the UILabel and is static and visible "underneath" the scrolling UITextView.

Also, I'm using an NSMutable Array with initWithObjectAndKeys. In this special case that is the only one of its kind in my UITableView, I use a special key that is only used by this particular part of the array. Is it possible to set it up so it's something regarding:

if (qux == *NSMutableArray with the special key*) {

    fooTextView.text = textString;

} else {

    fooTextLabel.text = textString;

}

And should I be using an if-else if statement or just an if-else statement?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天赋异禀 2025-01-03 11:55:10

使用 UITableView Delegate 方法 didSelectRowAtIndexPath:您可以从 NSIndexPath (indexPath.row) 获取行索引。您可以使用 if-then 或开关来确定哪个控件获取数据。确保将 UITableView 的委托属性设置为文件所有者,以便 UITableView 回调到您的控制器。

华泰

Use the UITableView Delegate method didSelectRowAtIndexPath: you can get you row index from the NSIndexPath (indexPath.row). The you can use an if-then or a switch to determine which of your controls gets the data. Make sure you set your UITableView's delegate property to your file owner so the UITableView will call back to you controller.

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文