1

I am just starting on Objective-C and XCode today.

I've made a

NSMutableArray

containing a bunch of strings.

I am looping through my array like this:

for (NSString *test in array) {
}

Now, how do I manage to show each of these values on the screen, standing underneath each other? I am not sure which UI element would be proper, and how to actually use that element (I don't know what element it is yet, but I only have knowledge on TextField, Button and Label so far).

2 Answers 2

2

Use a UILabel and set numberOfLines to 0 to have infinite lines.

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
myLabel.numberOflines = 0;
[self.view addSubview:myLabel];

NSString *testText = @"";
for (NSString *test in array) {
    testText = [testText stringByAppendingFormat:@"%@\n", text];
}
myLabel.text = testText;
Sign up to request clarification or add additional context in comments.

2 Comments

Can the amount on lines be edited on the go? So that every time it loops through the Array, it adds a new line?
That is not needed. You need to set the Frame of the label to create the size
1

You better make an UITableView number of rows at index path will be your [array count]; And at each cell, display [array objectAtIndex:indexPath.row]; If you need the whole code, tell me

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return array.count;
}
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                      reuseIdentifier:CellIdentifier];
    }

    cell.text = [array objectAtIndex:indexPath.row];
    return cell;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.