ios - Making a button read a string from an array -
i'm beginner developer ios. i'm using objective c develop app. want button able read string array. mean not set string button displays. want able string can use avspeechsynthesizser read string aloud. in advance
you don't provide code or details problem.
i have make assumption want read array while button tapped.
either using storyboard create button object , handler or manually add handler.
let's have button object named 'examplebutton', if choose manually add handler,
[examplebutton addtarget:self action:@selector(buttontapped:) forcontrolevents:uicontroleventtouchupinside];
let's array name examplearray
, , want access first element.
edit: use firstobject
instead objectatindex:0
since latter 1 crash app if array empty.
- (ibaction)buttontapped:(id)sender { // becareful, if array empty, firstobject return nil. // if use [examplearray objectatindex:0], crash id obj = [examplearray firstobject]; if ([obj iskindofclass:[nsstring class]]) { nslog(@"%@", obj); // have string object. } }
you have learn more if still cannot started above code.
Comments
Post a Comment