{"id":4082,"date":"2014-03-30T07:28:14","date_gmt":"2014-03-30T07:28:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/variable-iboutlet-name-for-a-uilabel-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:28:14","modified_gmt":"2014-03-30T07:28:14","slug":"variable-iboutlet-name-for-a-uilabel-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/variable-iboutlet-name-for-a-uilabel-collection-of-common-programming-errors\/","title":{"rendered":"Variable IBOutlet name for a UILabel?-Collection of common programming errors"},"content":{"rendered":"<p>You have the right idea, but you should pass <code>valueForKey:<\/code> to <code>self<\/code>, not <code>UILabel<\/code>, assuming its <code>self<\/code> that owns these properties.<\/p>\n<pre><code>myLabel = [self valueForKey:[NSString stringWithFormat:@\"label%d\", randomInt]];\n<\/code><\/pre>\n<p>As a side note, this is probably better done with an <code>IBOutletCollection<\/code>. In Xcode 4, select all of the labels and drag them to the header file. This will generate an <code>IBOutletCollection NSArray<\/code> containing all the outlets. You can then pick a random index from that array. It is usually unfortunate that <code>IBOutletCollection<\/code> stores its outlets in a non-deterministic order, but for your case it should be fine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You have the right idea, but you should pass valueForKey: to self, not UILabel, assuming its self that owns these properties. myLabel = [self valueForKey:[NSString stringWithFormat:@&#8221;label%d&#8221;, randomInt]]; As a side note, this is probably better done with an IBOutletCollection. In Xcode 4, select all of the labels and drag them to the header file. This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4082","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4082"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4082\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}