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

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
Following a tutorial, here, I was able to create a more customizable cells in a UITableView. When I click on the cells, however, they do not lead to another screen. I know that I am missing some coding, but I am unsure of how to add anything to what I have already mended. I have seen 'push-view' tutorials, but all of them have required an entirely different method of coding. I wish to keep my bunch of code intact (which is easier to edit and is more customizable, in my opinion), but add more code that will add a push-view feature. When a cell is clicked, I would like for a bunch of text information (for that specified cell), and maybe an image or two, to show. I would like to know how add a scrolling feature to page, as well. I appreciate any help you can provide.

(I know I have spelled 'beginning' wrong.)

RootViewController.h
Code:
#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController {
}

@end

RootViewController.m
Code:
#import "RootViewController.h"
#import "BegginingCell.h"


@implementation RootViewController


#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"Test";

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
 // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations.
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
 */


#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 4;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"BegginingCell";
    
    BegginingCell *cell = (BegginingCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"BegginingCell" owner:self options:nil];
		
		for (id currentObject in topLevelObjects) {
			if ([currentObject isKindOfClass:[BegginingCell class]]) {
				cell = (BegginingCell *) currentObject;
				break;
			}
		}
	}
				
    
	// Configure the cell.
	
if(indexPath.row == 0) {
	cell.test.text = @"Test";
	cell.myImage.image = [UIImage imageNamed:@"ButtonC.png"];
}	
	if(indexPath.row == 1) {
		cell.test.text = @"Hi";
	}
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
	/*
	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
	 [self.navigationController pushViewController:detailViewController animated:YES];
	 [detailViewController release];
	 */
}


#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

BegginingCell.h
Code:
#import <UIKit/UIKit.h>


@interface BegginingCell : UITableViewCell {
	IBOutlet UILabel *test;
	IBOutlet UIImageView *myImage;

}
@property (nonatomic, retain) IBOutlet UILabel *test;
@property (nonatomic, retain) IBOutlet UIImageView *myImage;
@end

BegginingCell.m
Code:
#import "BegginingCell.h"


@implementation BegginingCell
@synthesize test;
@synthesize myImage;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code.
    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state.
}


- (void)dealloc {
    [super dealloc];
}


@end

CustomCellsAppDelegate.h
Code:
#import <UIKit/UIKit.h>

@interface CustomCellsAppDelegate : NSObject <UIApplicationDelegate> {
    
    UIWindow *window;
    UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

CustomCellsAppDelegate.m
Code:
#import "CustomCellsAppDelegate.h"
#import "RootViewController.h"


@implementation CustomCellsAppDelegate

@synthesize window;
@synthesize navigationController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.
    
    // Set the navigation controller as the window's root view controller and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
	[navigationController release];
	[window release];
	[super dealloc];
}


@end

If screenshots from any of the XIB files would help, please request to see them. However, the linked video should give you idea of what I have done.

Thanks again, I really appreciate it.
 
Last edited:

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
Try adding stuff to the section where the template has this all commented out:

Code:
/*
	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
	 [self.navigationController pushViewController:detailViewController animated:YES];
	 [detailViewController release];
	 */
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
Try adding stuff to the section where the template has this all commented out:

Code:
/*
	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
	 [self.navigationController pushViewController:detailViewController animated:YES];
	 [detailViewController release];
	 */

I'm not entirely sure what to add, but I'll mess around with it. I'm really new at this stuff. Ha, ha.
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
Well, it depends on what you want to happen when someone presses a cell.

I wanted to have a page with an image and text following it. I wanted it to be scroll enabled as well, so that I could add a lot of text.
 

Shawnpk

macrumors 6502
Jan 13, 2011
350
0
Los Angeles, CA
Ok. So create a view that has the elements that you require and then in the method suggested earlier in this thread, initialize the view and use the pushViewController: animated: method that is in the commented out section of the above mentioned method.
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
Ok. So create a view that has the elements that you require and then in the method suggested earlier in this thread, initialize the view and use the pushViewController: animated: method that is in the commented out section of the above mentioned method.

Should I create some new files? For example, I want to add info onto the push view. So I name the files InfoViewController.h, InfoViewController.m, and Info.xib. To the XIB file I add a UITextView and a UIImage view? Or do I add a UIScrollView and add text and images into that?

I wouldn't know how to add that in the coding, however, and I wouldn't know what to do with the .h and .m files.
 

Shawnpk

macrumors 6502
Jan 13, 2011
350
0
Los Angeles, CA
Should I create some new files? For example, I want to add info onto the push view. So I name the files InfoViewController.h, InfoViewController.m, and Info.xib. To the XIB file I add a UITextView and a UIImage view? Or do I add a UIScrollView and add text and images into that?

I wouldn't know how to add that in the coding, however, and I wouldn't know what to do with the .h and .m files.

Yes, you can add a UIImageView and a UITextView to the .xib file and then push that view when a cell is pressed.
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
**Update

So here are my current files.

InfoViewController.h (I didn't do anything to it yet.)
Code:
#import <UIKit/UIKit.h>


@interface InfoViewController : UIViewController {

}

@end

InfoViewController.m (I didn't do anything to it yet.)
Code:
#import "InfoViewController.h"


@implementation InfoViewController

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

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

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end

In the RootViewController.m I uncommented and added some stuff. I don't know what to put in order to link it up with the .xib file. I change 'DetailViewController' to the file I created, 'InfoViewController'.
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
	
	 InfoViewController *detailViewController = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
	 // ...
     // Pass the selected object to the new view controller.
	 [self.navigationController pushViewController:detailViewController animated:YES];
	 [detailViewController release];
	 
}

I made the .xib file, InfoViewController.xib, added a UIImageView and a UITextView. I haven't linked it to any outlets though, since I don't have any corresponding code. I need a lot of help on that part... Ha, ha.
Screenshot2011-08-23at73620PM.png
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
I don't understand what you need help with...

Ha, ha... Sorry. I tend to over-explain.

In short, using the coding that I already have, I want to make it so that when you click on a cell it leads to a screen with an image and lots of text.

This is what I got so far, but the cells don't lead anywhere:
Screenshot2011-08-23at100419PM.png
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
Maybe you should tend to grab an iOS development book, to learn the basics first, or these threads can go on for ages.
Pushing new Views on top of your app-stack is one of the first things you learn in the books (exept code syntax/basics).
So I think it will take you less time reading up on those topics then keep getitng back here, copy/pasta'ing all the code.
My 2 cents.
If you're hardheaded like I used to be when I started. hit google.com on UINavigationController
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
Maybe you should tend to grab an iOS development book, to learn the basics first, or these threads can go on for ages.
Pushing new Views on top of your app-stack is one of the first things you learn in the books (exept code syntax/basics).
So I think it will take you less time reading up on those topics then keep getitng back here, copy/pasta'ing all the code.
My 2 cents.
If you're hardheaded like I used to be when I started. hit google.com on UINavigationController

It wouldn't hurt to try, I suppose.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
Don't spend a penny on books for the basics (besides The C Programming Language.) Just go to iTunes > Store > iTunes U > Stanford's iOS Programming lecuters. They cover everything you need to know as far as standard UIKit stuff.
 

ViviUO

macrumors 6502
Jul 4, 2009
307
22
If you post your entire project in a zip or something, I will take a look at it and get back to you.
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
Don't spend a penny on books for the basics (besides The C Programming Language.) Just go to iTunes > Store > iTunes U > Stanford's iOS Programming lecuters. They cover everything you need to know as far as standard UIKit stuff.

Alright. Thanks.

If you post your entire project in a zip or something, I will take a look at it and get back to you.

Sure. Here.

Thank you for your time.
 

ViviUO

macrumors 6502
Jul 4, 2009
307
22
I didn't see InfoViewController, so I created it myself and put a small sample together for you. I'm pretty sure I commented everything you need to know, but if not, email me at mike@petrocksoftware.com

Keep in mind, this is not the best way to do things, but it should be enough to get you on the right path.

You can also check my youtube channel for beginner tutorials .... table views are next on my list. :D

DOWNLOAD: TableView Example
 

Toastinator

macrumors newbie
Original poster
Aug 20, 2011
17
0
I didn't see InfoViewController, so I created it myself and put a small sample together for you. I'm pretty sure I commented everything you need to know, but if not, email me at mike@petrocksoftware.com

Keep in mind, this is not the best way to do things, but it should be enough to get you on the right path.

You can also check my youtube channel for beginner tutorials .... table views are next on my list. :D

DOWNLOAD: TableView Example

Wow, thanks a lot. I really appreciate your work. I'll be sure to check out your channel. =]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.