欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮

发布时间:2023/11/30 编程问答 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

一.NSMutableDictionary 

NSMutableDictionary  * tags;

1.NSMutableDictionary 添加内容:

[tags setValue:xxx forKey :xxx];

2.NSMutableDictionary 遍历:

for(NSString * title in tags){

   //其中得到的title是key

}

3.NSMutableDictionary 根据key取得value:

[tags valueForKey :xxx];


二.NSMutableArray

NSMutableArray *buttons;

1.NSMutableArray添加内容:

[buttons addObject:xxx];

2.NSMutableArray遍历:

for(xxxx *button in buttons){

}

三.动态添加按钮到view以及添加按钮点击事件:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect frame = CGRectMake(0,0,300,20);
[button setFrame:frame];
[button setTitle:@"xxx" forState:UIControlStateNormal];

[button addTarget:self action:@selector(xxxx) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

总结

以上是生活随笔为你收集整理的Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。