将 NSMutableArray 的随机 UIButtons 标题放入 NSMutablearray 的 UIButtons

Put Random UIButtons Title of NSMutableArray to UIButtons of NSMutablearray(将 NSMutableArray 的随机 UIButtons 标题放入 NSMutablearray 的 UIButtons)
本文介绍了将 NSMutableArray 的随机 UIButtons 标题放入 NSMutablearray 的 UIButtons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 3 个 UIButtons 的 NSMutableArray 和一个带有 50 个 UIButtons 的第二个 NSMutableArray.我想将这 3 个 UIButton 标题逐个字符地分配给 SecondArray 的每个 UIButton.但是 Second Array 的这 50 个 UIButton 中的每一个都已经有一个 Character.我的基本目的是首先我想检查每个 UIButton 的长度我的第一个数组的 uibutton 标题,然后将其按索引分配给第二个数组中的 UIButton.(对于 Exp,如果我的第一个按钮有标题堆栈",第二个结束"和第三个流"不我想分配索引的 UIButtons0-5 ,13-16,35-38 在第二个数组中).我的第一个数组有 3 个 UIBttons .这里是代码.

I have an NSMutableArray with 3 UIButtons and Second NSMutableArray with 50 UIButtons. I want to take these 3 UIButtons Titles to Assign it Character by Character to each UIButton of SecondArray.but Each of these 50 UIButtons of Second Array already have single Character.My Basics purpose is that first of all i want to check the length of each uibutton title of my first Array,then assign it to index by index to UIButton in Second Array.(For Exp if my first Button have titles "stack",second "over" and Third "flow" no i want to Assign UIButtons of index 0-5 ,13-16,35-38 in Second Array) .My first Array that have 3 UIBttons .here is code.

NSMutableArray *buttons = [NSMutableArray arrayWithObjects:btn1, btn2, btn3, nil];
            [btn1 setTitle:@"stack" forState:UIControlStateNormal]; 
            [btn2 setTitle:@"over" forState:UIControlStateNormal]; 
            [btn3 setTitle:@"flow" forState:UIControlStateNormal]; 

这是我的代码.创建 50 个 UIButton.

Here is my code.To create 50 UIButtons.

 -(void)button:(id)sender {
  saveBtn = [[NSMutableArray alloc] init];
  arr=[[NSArray alloc]
  initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",
     @"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",nil];

    for (int i=0; i<50; i++) {
            btn = [UIButton   buttonWithType:UIButtonTypeRoundedRect];
            btn.frame = CGRectMake(spacex, spacey, 30.0, 30.0);
            int idx;
            idx = arc4random()%[arr count];
            NSString* titre = [arr objectAtIndex:idx];
            [btn setTitle:titre forState:UIControlStateNormal];   
            spacex = spacex + 30;
            [saveBtn addObject:btn];
            [self.view addSubview:btn];

        }


            }

任何人都可以指导我如何将我的 UIButton 标题分配给特定索引上的这些 UIButton.谢谢

Any one guide me how can i assign my UIButton Titles to these UIButtons on Specific Index. Thanx

推荐答案

感谢每个人的帮助..但我在这里完成的是代码.我可以帮助其他人.

Thanx for helping Every one ..but i done it here is code.my be it help some one others.

 - (void)getbuttontitle {
   for(int i = 0;i<[buttons count];i++)
  {
     if(i == 0)
    {
     UIButton *b1 = [buttons objectAtIndex:0];
      a = (NSString *)[[b1 titleLabel] text];
        [storewords addObject:a];
        NSLog(@"b=%@",a);
        }
    else if(i == 1)
    {

    }
    else if(i == 2)
    { 

    }
 }
}

    for (NSString *str in storewords) {
        if (str==a) {
            int j = 0;
            int randn= (arc4random()%5)+1 ;
            NSLog(@"n=%d",randn);
            for (int i=randn; i<[a length]+randn; i++) {
                NSLog(@"a=%@",a);
                NSString *ichar  = [NSString stringWithFormat:@"%c", [a characterAtIndex:j]];
                UIButton*  b = [saveBtn objectAtIndex:i];
                NSLog(@"a=%@",ichar);
                j++;
                [b setTitle:ichar forState:UIControlStateNormal]; 
            }   
        }

        if (str==c) {


        }   

        if (str==d) {

        }       
    }

这篇关于将 NSMutableArray 的随机 UIButtons 标题放入 NSMutablearray 的 UIButtons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)