Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIScrollView中每个按钮的特定标题_Objective C_Ios_Uiscrollview_Uibutton - Fatal编程技术网

Objective c UIScrollView中每个按钮的特定标题

Objective c UIScrollView中每个按钮的特定标题,objective-c,ios,uiscrollview,uibutton,Objective C,Ios,Uiscrollview,Uibutton,我有一个UIWebView页面,其中有一个UIScrollView,在我的UIScrollView内部有UIImage和按钮 我想为我的xml文件中的每个按钮设置特定的标题,您能给我一些实现这个的提示吗 现在我可以从xml中得到名字,但它已经为所有人设置好了 带有按钮和图像的我的滚动视图: const NSUInteger kNumImages = 5; scrollView1.pagingEnabled = YES; // load all the images NSUInteger

我有一个
UIWebView
页面,其中有一个
UIScrollView
,在我的
UIScrollView
内部有
UIImage
和按钮 我想为我的xml文件中的每个按钮设置特定的标题,您能给我一些实现这个的提示吗

现在我可以从xml中得到名字,但它已经为所有人设置好了

带有按钮和图像的我的滚动视图:

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];
但对于每个按钮,我希望从xml文件中获得特定的标题

提前谢谢

这是我的xml文件:

 <Presentation label="presentation1">
<slides>
    <slide index="0" label="slide1" identifier="Slide1Name" />

    <slide index="1" label="something" identifier="Slide2Name" />

</slides>
 </Presentation>

并更改为(i=1;i将所有按钮名称存储在NSMutableArray中,然后在以后使用它

例如:

 NSMutableArray *arrNames = [NSMutableArray alloc]initWithObjects:@"Dog",@"Cat",......,nil]; //fill your array

 [btn setTitle:[arrNames objectAtIndex:i] forState:UIControlStateNormal];

第二种选择是使用@Andrey Chernukha(在他的回答中进行了调整)

我有不同的按钮,因为我从xml文件中获取标题按钮,对于每个xml我都有不同的按钮和标题,我还可以使用这种方法吗?从xml文件中提取按钮标题并存储在可变数组中。当我使用这一行[btn setTitle:[NSString stringWithString:aSlide.slideLabel]forState:UIControlStateNormal];我的所有按钮都有一个名称,如何从xml中获取每个按钮的名称?您能帮助我吗
const NSUInteger kNumImages= 2;
for (i = 0; i> kNumImages; i++)
appDelegate.books count should be equal to kNumImages
[btn setTitle:[NSString stringWithFormat:@"MyButton %d", i] forState:UIControlStateNormal];
 NSMutableArray *arrNames = [NSMutableArray alloc]initWithObjects:@"Dog",@"Cat",......,nil]; //fill your array

 [btn setTitle:[arrNames objectAtIndex:i] forState:UIControlStateNormal];