iphone - 如何将NSMutableArray值转换为NSString?

标签 iphone ios objective-c

我有名为* total的NSMutableArray和名为* lblTotal的UILabel。我从循环中得到结果值。现在,我想在UILabel中将此值设置为viewDidLoad。我怎样才能解决这个问题?

这是我正在使用的代码。

for(int counter = 0; counter < [node childCount]; counter++) {
            if ([[[node childAtIndex:counter] name] isEqualToString:@"Total"]){

                NSString *str = [[node childAtIndex:counter] stringValue];

                [total addObject:str];
                NSLog(@"Grand total is %@", total);
            }
        }

我只是想在NSString中设置结果值lbltotal.text = total。

最佳答案

NSArray  *array1 = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
NSString *joinedString = [array1 componentsJoinedByString:@","];

componentsJoinedByString: 将通过指定的字符串连接数组中的组件,并返回数组的字符串表示形式。

设置UILabel上的值
UILabel *label = [[UILabel alloc] init];
[label setText:joinedString];

关于iphone - 如何将NSMutableArray值转换为NSString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17986883/

相关文章:

objective-c - 从 json 数据填充类

iphone - 更改 UITableViewCell 中的删除附件 View

iphone - NSObject 默认构造函数

iPhone 应用程序上传后大小增加

ios - 如何在键盘已经打开的情况下呈现 JSQMessagesViewController?

ios - 需要从支付 key PayPal 获得交易 ID

iphone - 有多个函数调用而不是一个大的函数调用有任何性能增益/损失?

ios - 如何让默认用户代理在 header 中发送到服务器端

ios - 无法识别超出父 View 范围的 UILabel 上的点击

ios - 返回 __block 变量是如何工作的?