iPhone XCode - How to implement a UITableView
Tech-Today

iPhone XCode - How to implement a UITableView


In this demo I will extend the class UITableViewController, so I already have access to UITableViewDelegate and UITableViewDataSource classes.

Steps:
1.) Create a new window based project. Named it MyTable.

2.) I will explain the rest in codes:
MyTableAppDelegate.h
#import <UIKit/UIKit.h>
#import "MyTableViewController.h"

@interface MyTableAppDelegate : NSObject {
UIWindow *window;
MyTableViewController *myTableViewController; //custom class that extends UITableViewController
}

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

@end
MyTableAppDelegate.m
#import "MyTableAppDelegate.h"

@implementation MyTableAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
//call the custom class initializer
myTableViewController = [[MyTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
myTableViewController.view.frame = [UIScreen mainScreen].applicationFrame;

//add to the main window
[window addSubview:myTableViewController.view];
// Override point for customization after application launch
[window makeKeyAndVisible];
}


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

@end
#import <Foundation/Foundation.h>

@interface MyTableViewController : UITableViewController {
NSMutableArray *names; //table view data
}

@end
#import "MyTableViewController.h"

@implementation MyTableViewController

- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if(self) {
names = [[NSMutableArray alloc] initWithObjects:@"Ichi", @"Ni", @"San", nil];
}
return self;
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DefaultCell"];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"DefaultCell"] autorelease];
}
cell.text = [names objectAtIndex:indexPath.row];
return cell;
}

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
return [names count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [NSString stringWithFormat:@"Section %i", section];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *name = [names objectAtIndex:indexPath.row];
NSString *title = [NSString stringWithFormat:@"%@ selected!", name];
UIAlertView *view = [[UIAlertView alloc] initWithTitle:title message:@"Pressed" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[view show];
[view release];

[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellAccessoryDisclosureIndicator;
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [NSArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", nil];
}

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

@end




- Simple To-do List Using Core Data In Swift
Note: The steps 1-9 are all simply about setting-up the controllers. The main "core data" begins the next step after. Here's the finish project from step-1 to step-9. 1.) First, for us to have a better view, we have to disable the size classes....

- Mobile Development
iPhone / XCode DevelopmentCreate an iphone application using xcode that dynamically creates sqlite tablesMy Todo List iphone application development using xcodeiPhone Development Making the Slider control workHow TosCreate an image slide show in iphone...

- Create An Image Slide Show In Iphone Using Xcode
Here's how you can create image slide show from xcode - iphone Requirement:  -3 png images. 1.) Create a new View-based application project. Name it AnimationDemo. 2.) Once the new project is created. Add the 3 png images to the Resources folder....

- Iphone Xcode - Create A Simple Uiscrollview
Finally getting acquainted with iPhone's xcode. Now I'll build a simple window base application to demo the UIScrollView features. 1.) Create a new window base application, named it MyScroll. It should create 2 files: a.) MyScrollAppDelegate.h...

- Iphone Xcode - How To Create A Simple Uitabbar
A simple demonstration by code on how to implement a UITabBar on iPhone. 1.) Create a new Windows based project, and named it whatever you want. 2.) You should look up for 2 files, .h and .m (I named mine MyTab). MyTabAppDelegate.h #import <UIKit/UIKit.h>...



Tech-Today








.