Simple Table View in IOS
Step 1
Create a Project in xcode
Step 2
drag and drop the Table view in to ".xib" .
After Drag & Drop
Step 3
Click the Table View & click right mouse button .
set the dataSource & delegate into file owner.
Step 4
change the code like this ( add <UITableViewDelegate, UITableViewDataSource> )
//--------------------------------------------------------------------------------------------------
#import <UIKit/UIKit.h>
@interface TestViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray
*tableData; //variable
for holding the table data
}
@property(nonatomic,retain)NSArray *tableData;
@end
Step 5
synthesized the property
@synthesize tableData;
//-------------------------------------------------
//-------------------------------------------------
Step 6
add this code to viewDidLoad method in ".m"
//---------------------------------------------------------------------------------------------------------------------------
tableData = [NSArray arrayWithObjects:@"SLIIT 1st Year", @"SLIIT 2nd Year", @"SLIIT 3rd Year", @"SLIIT 4th Year",nil];
//---------------------------------------------------------------------------------------------------------------------------
add this code to viewDidLoad method in ".m"
//---------------------------------------------------------------------------------------------------------------------------
tableData = [NSArray arrayWithObjects:@"SLIIT 1st Year", @"SLIIT 2nd Year", @"SLIIT 3rd Year", @"SLIIT 4th Year",nil];
//---------------------------------------------------------------------------------------------------------------------------
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any
additional setup after loading the view, typically from a nib.
tableData = [NSArray arrayWithObjects:@"SLIIT
1st Year", @"SLIIT 2nd Year", @"SLIIT 3rd Year", @"SLIIT
4th Year",nil];
}
Step 7
Add following methods to ".m"
Add following 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];
return cell;
}
Step 8
Run the App
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)
- Custom Cell in UITableview
- Lazy Loading
- Pull to Refresh in TableView
- Working with keyboard in Objective C - Part 1
No comments:
Post a Comment