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 07-05-2010, 02:57 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default UITableView Problem

Hey,

I've got a TableView and I want that when I tap on one cell another TableView loads up.

So I wrote in my RootController.h:

Code:
 
#import <UIKit/UIKit.h>
#import "SecondViewController.h"

@interface RootViewController : UITableViewController <UITextFieldDelegate> {
	
	NSMutableArray *tableList;
}
@end
and in my .m :

Code:
@implementation RootViewController


#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];
	
	tableList = [[NSMutableArray alloc] init];
	[tableList addObject: @"The View"];
	[self setTitle: @"Table View"];
}

#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [tableList count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	[cell setText:[[tableList objectAtIndex:indexPath.row]retain]];
	[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

    return cell;
}



#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
	if ([[tableList objectAtIndex:indexPath.row] isEqual: @"The View"]) {
	
		SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
		[second setTitle:@"The View"];
		[self.navigationController pushViewController:second animated:YES];
		
	}
	
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}
@end
In my SecondViewController I've done the same (of course I adjusted it), but when I tap on one cell in the first ViewController only the empty SecondView loads up.

What's wrong?
Applekuchen is offline   Reply With Quote
Old 07-05-2010, 03:52 PM   #2 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

I don't understand what you mean by "only the empty view loads" but be careful, you're leaking memory all over.
Ice_2k is offline   Reply With Quote
Old 07-06-2010, 10:30 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

A view loads, on top of the view is the nav bar with the back button and the title. Under the nav bar is nothing.
Applekuchen is offline   Reply With Quote
Old 07-06-2010, 10:50 AM   #4 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

most likely you didn't connect something in IB
Ice_2k is offline   Reply With Quote
Old 07-06-2010, 10:52 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Germany
Posts: 56
Applekuchen is on a distinguished road
Default

I've done nothing in the IB. I created the Table Views without the IB.
Applekuchen is offline   Reply With Quote
Old 07-08-2010, 01:57 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 16
noobdev is on a distinguished road
Default

Quote:
Originally Posted by Applekuchen View Post
I've done nothing in the IB. I created the Table Views without the IB.
if ([[tableList objectAtIndex:indexPath.row] isEqual: @"The View"]) {

If your table is an array of NSString, this is going to be false. To compare strings you need to change the code to :

if ( [[tableList objectAtIndex:indexPath.row] isEqualToString:@"The View"])
noobdev is offline   Reply With Quote
Reply

Bookmarks

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: 331
6 members and 325 guests
anothermine, Chickenrig, givensur, michaelhansen, PixelInteractive, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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