ios - Load certain information from array index obj c -
i have array loads information plist so:
nsmutablearray *array = [[nsmutablearray alloc] initwithcontentsoffile:@"items.plist"];
here how plist looks like:
<array> <dict> <key>string</key> <string>str</string> <key>id</key> <string>0</string> </dict> <dict> <key>string</key> <string>str2</string> <key>id</key> <string>1</string> </dict> <dict> <key>string</key> <string>str3</string> <key>id</key> <string>2</string> </dict> <dict> <key>string</key> <string>str4</string> <key>id</key> <string>35</string> <key>data</key> <string>5</string> </dict> </array>
i have created for-loop creates uibutton every string there in plist, how check in loop if index contain 'data' key? check if index has data can set image button.
something should work:
nsmutablearray *array = [[nsmutablearray alloc] initwithcontentsoffile:@"items.plist"]; (nsdictionary * dict in array) { uibutton * newbtn = [uibutton buttonwithtype:uibuttontypesystem]; [newbtn settitle:dict[@"id"] forstate:uicontrolstatenormal]; // -- update comment -- // // see if data exists if (dict[@"data"]) { // if data's value image ... [newbtn setimage:dict[@"data"] forstate:uicontrolstatenormal]; // in question values @"data" integers, make sure don't try add image. } // other stuff button ... }
Comments
Post a Comment