UITableView Example

UITableView is the basic list view available in iphone development, with the help of [uitableview] we can list out the values in the single column an in multiple row format. uitableview is the useful in the many of the iphone development. uitableview is ver easy to implement in the xcode.
Here is the example to implement the uitableview for the beginners 
Step 1.  
Open xcode create new project and add the UITableView control in you view controller. Just drag drop the uitableview view in view. And then set the delegate for the delegate with the file’s owner.refer the below image
Step 2.
Write the following code in your .h file
#import <UIKit/UIKit.h>
@interface UITableViewViewController : UIViewController <UITabBarDelegate,UITableViewDataSource>
{
    NSArray     *UITableviewExample;
}
@end
Write the following code in your .m file
#pragma mark - View lifecycle

- (void)viewDidLoad
{
    UITableviewExample = [[NSArray alloc] initWithObjects:@"Iphone Developer",@"Android Developer",@"BlackBerry Developer", nil];
    [super viewDidLoad];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [UITableviewExample count];
}

- (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];
    }
    
    cell.textLabel.text = [UITableviewExample objectAtIndex:indexPath.row];
    
    return cell;
}
Now just run the program you will get the following output 



Powered by Blogger.
Twitter Delicious Facebook Digg Stumbleupon Favorites More