iOS 视图的tag使用详解

iOS 的tag说明,看到有些使用tag,将tag的值设置为10000 这么大的值,我感觉可能是写这个值得怕这个tag已经被别的控件使用,因此设的大点,不过这样使用的可能是没有搞清楚tag的作用范围,tag的作用范围不是整个App的而是这个View及其SubView,苹果官方的解释是:

object-c

- ( a logicalPath='//apple_ref/doc/c_ref/__kindof' href='' data-id='//apple_ref/doc/c_ref/__kindof'__kindof /a UIView *)viewWithTag:(NSInteger)tag

Parameters

tag

The tag value to search for.

Return Value

The view in the receiver’s hierarchy whose tag property matches the value in the tag parameter.

Discussion

This method searches the current view and all of its subviews for the specified view.

tag

Property

An integer that you can use to identify view objects in your application.

Declaration

SWIFT

var tag: Int

OBJECTIVE-C

@property(nonatomic) NSInteger tag

Discussion

The default value is 0. You can set the value of this tag and use that value to identify the view later.


你可能感兴趣的:(iOS 视图的tag使用详解)