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 12-21-2010, 01:13 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 4
goods003 is on a distinguished road
Default table view for different sections

I've been struggling on getting this to work. I have a list in a table view on my first page that i have split into 2 sections. When i select one of my items I will have another table view. The problem is the first section repeats itself in the second section because it doesnt recognize different sections. It just repeats itself from the other one. I have a feeling i could do this using the if statement but i'm not sure on how to implement that. I'm not sure if this is making any sense, respond for further explanation.
goods003 is offline   Reply With Quote
Old 12-21-2010, 03:07 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    static NSString *CellIdentifier1 = @"Cell1";
    if(indexPath.section == 0) {
        if(indexPath.row == 0) {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                UITextField *textField;
                if (cell == nil) {
                        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                        cell.textLabel = @"Cell 1 of section 1";

                        textField = [[[UITextField alloc] init] autorelease];
                        textField.delegate = self;
                        textField.borderStyle = UITextBorderStyleRoundedRect;
                        textField.tag = 100;
                        [cell.contentView addSubView textField];
 
                }else{
                     textField = (UITextField *) [cell viewWithTag:100];

                }
                return cell;
        }
        else if(indexPath.row == 1) {
                UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
                if (cell1 == nil) {
                cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
                cell1.textLabel = @"Cells 2 of section 1"; //this cell is w\o textfield
                }
                return cell1;
        }
    }
    else if(indexPath.section == 1) {
        if(indexPath.row == 0) {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                if (cell == nil) {
                        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                        cell.textLabel = @"Cells 1 of section 2";
                }
                return cell;
        }
        else if(indexPath.row == 1) {
                UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
                if (cell1 == nil) {
                        cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
                        cell1.text = @"Cells 2 of section 2";
                }
                return cell1;
        }
    }
}
__________________
dany_dev is offline   Reply With Quote
Old 12-21-2010, 10:07 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 4
goods003 is on a distinguished road
Default

Thank you for the response. I have a problem though. At all the
Code:
cell1.textLabel = @"Cells 2 of section 1";
I get an error saying object cannot be set. I have a feelings it's something stupid, but I'm pretty new to this. Also I was wondering so does this affect my lists in my sections in my viewdidload and my arrays that i need in the correct rows in my didselectrowatindexpath?
goods003 is offline   Reply With Quote
Old 12-21-2010, 10:15 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Code:
cell1.textLabel = @"Cells 2 of section 1";
textLabel is the label, but you are assigning a string to it. What you actually want is the label's text property.

Code:
cell1.textLabel.text = @"Cells 2 of section 1";
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 12-21-2010, 11:21 AM   #5 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

yes, a little typo .
__________________
dany_dev is offline   Reply With Quote
Old 12-21-2010, 11:50 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 4
goods003 is on a distinguished road
Default

Once again thank you for the help. Right now this is just causing the app to crash. But I'm not sure if this would fix my issue though. My issue is more at the didselectrowatindexpath. I understand that new section would mean new row (i.e. section 0 and section 1 both have row 0 and so on. So I'm trying to get my information in the correct sections.

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	// Pass the selected object to the new view controller.

	NSArray* example0 = nil;
	
	switch (indexPath.section == 0, indexPath.row)
	
	{
		case 0:
			example0 = [NSArray arrayWithObjects:@"info", @"info",  nil];
			break;
		case 1:
		        example0 = [NSArray arrayWithObjects:@"info", @"info", nil];
			break;
		case 2:
			example0 = [NSArray arrayWithObjects:@"info", @"info", nil];
			break;
		case 3:
			example0 = [NSArray arrayWithObjects:@"info", @"info", nil];
			break;
		case 4:
			example0 = [NSArray arrayWithObjects:@"info", @"info", nil];
			break;
		default:
			break;
	}
	
	NSArray* example1 = nil;
	
	switch (indexPath.section == 1, indexPath.row)
	{
		case 0:
			example1 = [NSArray arrayWithObjects:nil];
			break;
		case 1:
			example1 = [NSArray arrayWithObjects:nil];
			break;
		case 2:
			example1 = [NSArray arrayWithObjects:nil];
			break;
		default:
			break;
	}
	
	if (example0)
	{
		RoutTableViewController* rtvc = [RoutTableViewController routTableViewControllerWithRoutNames:example0];
		[self.navigationController pushViewController:rtvc animated:YES];
	}
	
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
goods003 is offline   Reply With Quote
Reply

Bookmarks

Tags
array, rows, sections, table view, tableview

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: 397
9 members and 388 guests
chemistry, daudrizek, HemiMG, jeroenkeij, Kirkout, PavelMik, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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