Penguin
Penguin

Reputation: 953

How to separate NSArray values?

NSArray has 3 values

@[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"]

And I want to put this array into the UILabel with word wrap. So when I run, it should show like this in label.

addd:etyrhetwrwr
fdfdd:jjjjhhhh
fsuy:jjhwgggggg

But I can't separate this NSArray. How can I do that?

Upvotes: 0

Views: 218

Answers (4)

Bevin Patel
Bevin Patel

Reputation: 302

Try This

NSArray *yourArray = @[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"];
NSString *string = [myArray componentsJoinedByString:@"\n"];
[yourLabel setText:string];

Upvotes: 1

Deepak
Deepak

Reputation: 1441

try this code

    NSArray *array = [[NSArray alloc] initWithObjects:@"adad",@"fgfdgdfg",@"sddgfs", nil];
    NSMutableString *strFinalData = [[NSMutableString alloc] init];

    for (int i=0; i<[array count]; i++)
    {
        [strFinalData appendFormat:@"%@ ",[array objectAtIndex:i]];
    }

    NSLog(@"Final String: %@",strFinalData);

Now set yourLabel.text = strFinalData;

Upvotes: 0

user4079229
user4079229

Reputation:

You can separate NSArray in UILabel by

NSArray myArr = @[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"];
NSString strLabel = [myArr string:@"\n"];

Upvotes: 0

Nicola Miotto
Nicola Miotto

Reputation: 3706

NSArray *myArray = @[@"addd:etyrhetwrwr", @"fdfdd:jjjjhhhh", @"fsuy:jjhwgggggg"];
NSString *labelString = [myArray componentsJoinedByString:@"\n"];

Then use the labelString to set your label text property.

Upvotes: 3

Related Questions