Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议提供根据indexPath返回title的方法 #40

Closed
yuhechuan opened this issue May 31, 2017 · 3 comments
Closed

建议提供根据indexPath返回title的方法 #40

yuhechuan opened this issue May 31, 2017 · 3 comments

Comments

@yuhechuan
Copy link
Contributor

有时候通过buttonIndex 来讨论容易出错 不易读

iTofu pushed a commit that referenced this issue May 31, 2017
增加bottonIndex 换取title的方法, About #40
@iTofu
Copy link
Owner

iTofu commented May 31, 2017

#41 Merged.
谢谢,这的确是一个便利方法,但我不认同你的阐述,Index 是始终唯一的而业务数据不是。
具体来讲,buttonIndex 是可以唯一标识每一个 button 的,而 buttonTitle 不会,buttonTitle 在逻辑上是允许相同的(当然一般业务上应该不允许)。比如给一个特定条件查找数组中的某个变量,一般函数设计都是返回该变量下标,而不是直接返回该变量(这也涉及微小的 I/O 优化)。
至于可读性,#41 提供的方法我认为是 convenience。每一个 title 都是外部传给 actionSheet 的,在明确 index 的情况下获取 buttonTitle 其实并不需要通过 actionSheet:

初始化 actionSheet 时:
| 外部 | -- titles --> | actionSheet |
↑ 外部是明确持有所有 titles 的,并在初始化 actionSheet 时传递给了 actionSheet

根据 index 获取 title:
外部持有所有 titles,直接根据 index 获取对应 title 即可,并不需要把通过 index 去 actionSheet 中读取再返回该 title。

@yuhechuan
Copy link
Contributor Author

是的下标的确是不可或缺的,大神研究的很专业,学习了,我没有想那么多,哈哈.只是在用的时候发现一些.

@iTofu
Copy link
Owner

iTofu commented Jun 2, 2017

过奖,相互学习吧。

@iTofu iTofu closed this as completed Jun 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants