Load Distinct Images from array into UITabeView
Step 1
Create Project (UITableView) by using this tutorial
Step 2
Add images to your project
Step 3
Goto the " .h " file of you
change the code like this
// ViewController.h
// ImageTableviewExample
//
// Created by Apple on
4/22/13.
// Copyright (c) 2013
Dhanushka Adrian. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
{
NSArray
*tableData; //variable
for holding the table data
NSArray
*tableImageData; //variable
for holding the images
}
@end
Step 4
Goto " .m " file
change the code like this
//
// ViewController.m
// ImageTableviewExample
//
// Created by Apple on
4/22/13.
// Copyright (c) 2013
Dhanushka Adrian. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize tableData,tableImageData;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any
additional setup after loading the view, typically from a nib.
//
Initialize table data
tableData = [NSArray arrayWithObjects:@"SLIIT
- Malabe", @"SLIIT - Kollupitiya", @"SLIIT
- Matara",nil];
tableImageData=[NSArray arrayWithObjects:@"images1.jpeg", @"images2.jpeg", @"images3.png",nil];
}
Step 5
Add following two methods to ".m"
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString
*simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[tableImageData objectAtIndex:indexPath.row]];
return cell;
}
Characteristic of cell object
The
UITableViewCell
class defines three properties for this cell content:
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[tableImageData objectAtIndex:indexPath.row]];
Good Luck!
Tutorial List
- SQLite Based iPhone Application
- json with IOS (Basic) - Tutorial
- Simple Table View in IOS
- Load Distinct Images from array into UITableView
- Simple UIPickerView Example
- Tab Bar Application Part 1
- Tab Bar Application Part 2
- Tab Bar Application Part 3 ( with Login Screen )
- Tab Bar Application Part 4 ( Navigation )
- Table View Design in IOS Part 1
- Table View Design in IOS Part 2 ( Time Table )
- How to Add search bar in Table View
- Local Notification in IOS
- Core Data (For Beginners )
- Core Data Tute 2 (Add/Delete/Search)
- Core Data Tute 3 (Two table)
No comments:
Post a Comment