//
// myViewController.h
//
// Created by Weerachai on 10/27/55 BE.
// Copyright (c) 2555 Weerachai. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface myViewController : UITableViewController
@end
myViewController.m
//
// myViewController.m
//
// Created by Weerachai on 10/27/55 BE.
// Copyright (c) 2555 Weerachai. All rights reserved.
//
#import "myViewController.h"
@interface myViewController ()
{
NSMutableArray *myObject;
}
@end
@implementation myViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myObject = [[NSMutableArray alloc] init];
[myObject addObject:@"ThaiCreate.Com 1"];
[myObject addObject:@"ThaiCreate.Com 2"];
[myObject addObject:@"ThaiCreate.Com 3"];
[myObject addObject:@"ThaiCreate.Com 4"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return myObject.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// Use the default cell style.
cell = [[[UITableViewCell alloc] initWithStyle : UITableViewCellStyleSubtitle
reuseIdentifier : CellIdentifier] autorelease];
}
NSString *cellValue = [myObject objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellValue = [myObject objectAtIndex:indexPath.row];
UIAlertView *alert =[[UIAlertView alloc]
initWithTitle:@"คุณเลือกรายการ"
message:cellValue
delegate:self
cancelButtonTitle:@"ปิด"
otherButtonTitles: nil];
[alert show];
}
@end