質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

Q&A

解決済

1回答

1178閲覧

const char *arrayをNSArrayに変換したい

nakamu

総合スコア82

Objective-C

Objective-Cはオブジェクト指向型のプログラミング言語のひとつです。C言語をベースにSmalltalkが取り入れられています。

0グッド

0クリップ

投稿2020/03/09 10:22

編集2020/03/09 10:25

コードはUnityからiOSのアクションシートを呼び出すためのネイティブ側になります。
文字列の変換はわかったのですが、アクションシートに表示する項目用のarrayの変換方法が見つかりません。

ObjectiveC

1#import "iOSAlertDialog.h" 2 3extern "C" { 4 void showActionSheet(const char *gameObjectName, const char *callbackMethodName, const char *itemArray[]) { 5 NSString *gameObject = [NSString stringWithCString:gameObjectName encoding:NSUTF8StringEncoding]; 6 NSString *method = [NSString stringWithCString:callbackMethodName encoding:NSUTF8StringEncoding]; 7 8 NSArray *items = itemArray; **←ココです** 9 10 iOSAlertDialog *alertDialog = [[iOSAlertDialog alloc] init]; 11 [alertDialog gameObject:gameObject 12 method:method 13 items:items]; 14 } 15} 16 17@implementation iOSAlertDialog 18 19- (void) gameObject:(NSString* )gameObject method:(NSString *)method items:(NSArray* )items { 20 _alertController = [UIAlertController alertControllerWithTitle:nil 21 message:nil 22 preferredStyle:UIAlertControllerStyleActionSheet]; 23 24 [items enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) { 25 [_alertController addAction:[UIAlertAction actionWithTitle:obj 26 style:UIAlertActionStyleDefault 27 handler:^(UIAlertAction * _Nonnull action) { 28 UnitySendMessage([gameObject UTF8String], [method UTF8String], [obj UTF8String]); 29 }]]; 30 }]; 31 32 [_alertController addAction:[UIAlertAction actionWithTitle:@"キャンセル" 33 style:UIAlertActionStyleCancel 34 handler:^(UIAlertAction * _Nonnull action) { 35 UnitySendMessage([gameObject UTF8String], [method UTF8String], [@"キャンセル" UTF8String]); 36 }]]; 37 UIViewController *viewController = UnityGetGLViewController(); 38 [viewController presentViewController:_alertController animated:true completion:nil]; 39} 40 41@end 42

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

こんなんでいかがでしょう。

objc

1 NSMutableArray *items = [[NSMutableArray alloc] init]; 2 for (const char **p = itemArray; *p != NULL; p++) { 3 [items addObject: [NSString stringWithCString:*p encoding:NSUTF8StringEncoding]]; 4 }

投稿2020/03/09 11:46

hoshi-takanori

総合スコア7893

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nakamu

2020/03/09 14:44

ありがとうございます! Unity側でアクションシート使い回しできるコードになりました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問