Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-18-2012, 01:57 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 6
jonwizard is on a distinguished road
Question Objective-C if-else or if-else if statement

I have both a UITextLabel and a UITextView occupying the same real estate, point-for-point in my view. I have an NSMutableArray allocated to populate the UITextLabel based on what the user taps in a table. I would also like to program the app to use the UITextView if and only if the user taps on one specific row. I think this can be accomplished with an if-else or if-else if statement, but I'm not sure. If that will work, I don't know what to put in the if part of the code. So far, I have this:

if (qux == ??) {

fooTextView.text = textString;

} else {

fooTextLabel.text = textString;

}

I don't know what to set the if statement to. I tried to set it to

if (qux == the really long code containing the single array statement I want displayed as a UITextView)

but that returned an error. Does anyone have a suggestion on how to get Xcode to recognize my single NSMutableArray table cell with the UITextView and not (also) with the UILabel? As of right now, the app builds but displays the text both in the UITextView, so it scrolls and does exactly what I want and also in the UILabel but is static and visible "underneath" the scrolling UITextView.

Also, I'm using an NSMutable Array with initWithObjectAndKeys. In this special case that is the only one of its kind in my UITableView, I use a special key that is only used by this particular part of the array. Is it possible to set it up so it's something regarding:

if (qux == NSMutableArray with the special key) {

fooTextView.text = textString;

} else {

fooTextLabel.text = textString;

}

And should I be using an if-else if statement or just an if-else statement?
jonwizard is offline   Reply With Quote
Old 01-18-2012, 02:29 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 304
fiftysixty is on a distinguished road
Default

Quote:
Originally Posted by jonwizard View Post
I have both a UITextLabel and a UITextView occupying the same real estate, point-for-point in my view. I have an NSMutableArray allocated to populate the UITextLabel based on what the user taps in a table. I would also like to program the app to use the UITextView if and only if the user taps on one specific row. I think this can be accomplished with an if-else or if-else if statement, but I'm not sure. If that will work, I don't know what to put in the if part of the code. So far, I have this:

if (qux == ??) {

fooTextView.text = textString;

} else {

fooTextLabel.text = textString;

}

I don't know what to set the if statement to. I tried to set it to

if (qux == the really long code containing the single array statement I want displayed as a UITextView)

but that returned an error. Does anyone have a suggestion on how to get Xcode to recognize my single NSMutableArray table cell with the UITextView and not (also) with the UILabel? As of right now, the app builds but displays the text both in the UITextView, so it scrolls and does exactly what I want and also in the UILabel but is static and visible "underneath" the scrolling UITextView.

Also, I'm using an NSMutable Array with initWithObjectAndKeys. In this special case that is the only one of its kind in my UITableView, I use a special key that is only used by this particular part of the array. Is it possible to set it up so it's something regarding:

if (qux == NSMutableArray with the special key) {

fooTextView.text = textString;

} else {

fooTextLabel.text = textString;

}

And should I be using an if-else if statement or just an if-else statement?
You didn't really tell us that the "qux" in your code is, but here's how I'd go about doing things. If you know where in your table the one specific row is (it is fixed) then it's simply a matter of implementing

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == specificCellRow) {
        textView.hidden = NO;
        textView.text = @"text";
        textLabel.hidden = YES;
    } else {
        textLabel.hidden = NO;
        textLabel.text = @"text";
        textView.hidden = YES;
    }
}
fiftysixty is offline   Reply With Quote
Old 01-18-2012, 11:26 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 6
jonwizard is on a distinguished road
Default

Quote:
Originally Posted by fiftysixty View Post
You didn't really tell us that the "qux" in your code is, but here's how I'd go about doing things. If you know where in your table the one specific row is (it is fixed) then it's simply a matter of implementing

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == specificCellRow) {
        textView.hidden = NO;
        textView.text = @"text";
        textLabel.hidden = YES;
    } else {
        textLabel.hidden = NO;
        textLabel.text = @"text";
        textView.hidden = YES;
    }
}
That's exactly what I was looking for. "qux" was the name of the array, but I guess that's irrelevant because the code needs to point to indexPath.row, not the array as whole?

So, I threw that code in, but don't know what to change "specificCellRow" to. I played around with it for a few minutes, but everything I tried returned an error. I want it to point to cell #1 in the UITableView. If it's the same result via a different method, could it also point to that specific data in the array? The only problem with that is my NSMutableArray is set up as:

array = [[NSMutableArray alloc] init];

array addObject: [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Steve", @"name", @"Male", @"gender", nil];

array addObject: [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Mike", @"name", @"Male", @"gender", nil];

array addObject: [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Pete", @"name", @"Male", @"gender", nil];

etc.
jonwizard is offline   Reply With Quote
Old 01-18-2012, 03:44 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 304
fiftysixty is on a distinguished road
Default

Quote:
Originally Posted by jonwizard View Post
That's exactly what I was looking for. "qux" was the name of the array, but I guess that's irrelevant because the code needs to point to indexPath.row, not the array as whole?

So, I threw that code in, but don't know what to change "specificCellRow" to. I played around with it for a few minutes, but everything I tried returned an error. I want it to point to cell #1 in the UITableView. If it's the same result via a different method, could it also point to that specific data in the array? The only problem with that is my NSMutableArray is set up as:

array = [[NSMutableArray alloc] init];

array addObject: [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Steve", @"name", @"Male", @"gender", nil];

array addObject: [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Mike", @"name", @"Male", @"gender", nil];

array addObject: [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Pete", @"name", @"Male", @"gender", nil];

etc.
indexPath.row is simply the row index number, starting from 0 if I remember correctly. If you table doesn't have sections, you don't have to worry about anything else. If you have sections, then the indexPath will have both the index of the section and the index of the cell in that section.
fiftysixty is offline   Reply With Quote
Old 01-18-2012, 07:10 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 6
jonwizard is on a distinguished road
Default Thanks!

Quote:
Originally Posted by fiftysixty View Post
indexPath.row is simply the row index number, starting from 0 if I remember correctly. If you table doesn't have sections, you don't have to worry about anything else. If you have sections, then the indexPath will have both the index of the section and the index of the cell in that section.
Fantastic, thanks for the help!
jonwizard is offline   Reply With Quote
Reply

Bookmarks

Tags
array, elseif, nsmutablearray, nsstring, xcode 4.2.1

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
9 members and 390 guests
7twenty7, Atatator, glenn_sayers, guusleijsten, iphonedevshani, QuantumDoja, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0