Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

animefx

macrumors regular
Original poster
May 10, 2005
157
0
Illinois
I mostly finished with my 1st iPhone app, but I'm having one issue I'm having trouble resolving.

I have 3 labels and just below that a single UITextView control. I'm looping through a for statement and outputting the data to the TextView using NSString withFormat method. The problem is I want each part to be left aligned with it's corresponding label above. Each time through the loop I use 2 \n\n and then append the string on the previous so I have a list of data in my TextView. It gets kind of sloppy though. I realize I might be able to use a tableview a bit more effectively for something like this but as far as I can tell you can make tableviews transparent and that's how I have my TextView currently.

Any suggestions?
 
Does the next need to be editable? If you're just displaying text, you're probably better off using UILabels instead of UITextView. UILabels can be multi-line.
 
labels is a good idea but the problem is I could be displaying a little data or a lot of data and I want the user to be able to scroll through them. I suppose I could create a scroll view and create the labels during runtime for every piece of data but that would probably be a pain
 
I wrote a class called return a certain number of spaces to put in-between other objects in my textview depending upon the length of what's in my variables. Works flawlessly:

Code:
#import "FormatSpacing.h"

@implementation FormatSpacing

- (NSString *) LengthOfIncorrect: (int) a{
   
    switch (a) {
        case 1:
            return @"          ";
            break;
        case 2:
            return @"        ";
            break;
        case 3:
            return @"      ";
            break;
        default: //aka case 0, 4, 5, etc
            return @"error";
            break;
    }
    
}


- (NSString *) LengthOfCorrect: (int) b{
    
    switch (b) {
        case 1:
            return @"         ";
            break;
        case 2:
            return @"       ";
            break;
        case 3:
            return @"     ";
            break;
        default: //aka case 0, 4, 5, etc
            return @"error";
            break;
    }
    
}

@end

Maybe a screenshot of what the issue is would
help.
 
labels is a good idea but the problem is I could be displaying a little data or a lot of data and I want the user to be able to scroll through them. I suppose I could create a scroll view and create the labels during runtime for every piece of data but that would probably be a pain

So you want each bit of text to be individually scrollable? That doesn't sound like a good UI design!

But if that's what you really want to do, you can put each label inside it's own scrollview. (There's no reason you can't do this in Interface Builder, if there's a fixed number of labels).

However, I think a better approach, in terms of UI, would be to use a UITableView. If you don't want the table to get too long, put a 2-3 line summary of the text in each table cell (UILabel can automatically display a "..." at the end). When the user taps on the cell, push a detail view controller that contains the full text.
 
Its just 1 textview divided into 3 colums... the reason I went with the textview vs. tableview is I need the textview to be transparent. It's important they see all the information on the screen at once vs. having to go through multiple screens.

I'll post a screenshot later tonight so you guys can see what I mean. I'm fickle about design too, but I think you guys will approve :)

So you want each bit of text to be individually scrollable? That doesn't sound like a good UI design!

But if that's what you really want to do, you can put each label inside it's own scrollview. (There's no reason you can't do this in Interface Builder, if there's a fixed number of labels).

However, I think a better approach, in terms of UI, would be to use a UITableView. If you don't want the table to get too long, put a 2-3 line summary of the text in each table cell (UILabel can automatically display a "..." at the end). When the user taps on the cell, push a detail view controller that contains the full text.


----------

I just noticed I could use "short" instead of int in those methods. Save a little bit of memory.
 
I just noticed I could use "short" instead of int in those methods. Save a little bit of memory.

Hmm, I wouldn't recommend that. In many cases you won't actually be saving any memory because of alignment. And even when you do, the savings aren't significant until you have at least 10s or 100s of thousands of instances.

It's also a bad habit to get in to, because you'll get weird hard-to-diagnose problems one day when you accidentally do overflow a short...
 
Last edited by a moderator:
There's probably no reason to ever use short for anything.

Stack memory is free, as long as you don't run out. The difference in stack memory used for a handful of shorts or ints isn't significantly different.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.