In this tutorial we will create the table view. and each cell of the table show the different-2 values. Here are some steps for it…
1.Open the xcode & choose "File->New Project".
2.Select "Application" from left menu and then "View-based Application".
3.Name your project as "table view" and save the project.
4.Now just select "table_viewViewController.h" file from left menu for define a table view. Set the property,delegate and datasource for table view.
#import
@interface table_viewViewController : UIViewController
{
IBOutlet UITableView *table;
NSMutableArray *arrayno;
}
@property (nonatomic,retain) UITableView *table;
@end
5. Now select "table_viewViewController.m" file from menu for implementation.
#import "table_viewViewController.h"
@implementation table_viewViewController
@synthesize table;
- (void)viewDidLoad {
arrayno=[NSMutableArray arrayWithObjects:@"100",@"200",@"300",@"400",@"500",nil];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrayno 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] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSString *cellValue = [arrayno objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
6. Now double click on "table_viewViewController.xib" from Resource folder for open it.
7. On the view window drag the table view from library . Then link the tableview to the File's Owner.
8. Then Quit and Save the Interface Builder.
9. Now you are ready for click on "Build & Go" button.
Now you can see the output in iphone simulator .
More posts of this quialty. Not the usual c***, please
(1) Responses to this post