xml ファイルから各ボタンに特定のタイトルを設定したいのですが、これを実装するためのヒントを教えてくださいUIWebView
。UIScrollView
UIScrollView
UIImage
現在、xml から最初の名前を取得できますが、すべての名前が設定されています
ボタンと画像を含む私のscrollView:
const NSUInteger kNumImages = 5;
scrollView1.pagingEnabled = YES;
// load all the images
NSUInteger i;
for (i = 1; i<= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.userInteractionEnabled = YES;
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
[scrollView1 addSubview:imageView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];
Presentation1Name *aSlide = [appDelegate.books objectAtIndex:0];
NSLog(@" %@", aSlide.slideLabel );
[btn setTitle:[NSString stringWithString:aSlide.slideLabel]
forState:UIControlStateNormal];
btn.frame = rect;
[btn setTag:i];
[btn addTarget:self action:@selector(buttonClick:)
forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];
}
[self layoutScrollImages];
}
コードを使用しているすべてのボタンのタイトルを追加する
[btn setTitle:[NSString stringWithString:aSlide.slideLabel]
forState:UIControlStateNormal];
しかし、ボタンごとに、xmlファイルから特定のタイトルが必要です
前もって感謝します!
ここに私のxmlファイルがあります:
<Presentation label="presentation1">
<slides>
<slide index="0" label="slide1" identifier="Slide1Name" />
<slide index="1" label="something" identifier="Slide2Name" />
</slides>
</Presentation>
編集:
Presentation1Name *aSlide = [appDelegate.books objectAtIndex:0]; を追加すると objectAtIndex to i このエラーが発生します
objectAtIndex を追加すると: プロセスが終了しました * キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了しています, 理由: '-[NSPlaceholderString initWithString:]: nil argument' * * First throw call stack: (0x1c95012 0x10d2e7e 0x1c94deb 0xae97f5 0xae9774 0x3d64 0x4723 0x10e6705 0x1d920 0x1d8b8 0xde671 0xdebcf 0xddd38 0x4d33f 0x4d552 0x2b3aa 0x1ccf8 0x1bf0df9 0x1bf0ad0 0x1c0abf5 0x1c0a962 0x1c3bbb6 0x1c3af44 0x1c3ae1b 0x1bef7e3 0x1bef668 0x1a65c 0x295d 0x2885 0x1) libc ++abi.dylib: 例外をスローして呼び出された終了 (lldb)
そしてそれは
-[NSPlaceholderString initWithString:]: nil 引数'
その後、xml ファイルにラベルが 2 つしかないため、5 t0 2 を変更します。
const NSUInteger kNumImages= 2;
また、 for (i = 1; i<= kNumImages; i++) に変更します
for (i = 0; i> kNumImages; i++)
それでも「正しく動作しない」
私の質問はどうすればこれを行うことができますか
appDelegate.books count should be equal to kNumImages