-
Notifications
You must be signed in to change notification settings - Fork 0
TableView Objective c 0
-
@interface ViewController () <UITableViewDelegate,UITableViewDataSource> .
-
@property (strong,nonatomic) UITableView *table;
-
@property (strong,nonatomic) NSArray *content; . .
-
@end .
-
@implementation ViewController .
-
- (void)viewDidLoad {
-
[super viewDidLoad];
-
[self cofigureTableview];
-
self.content = @[ @"Monday", @"Tuesday", @"Wednesday",@"Thursday",@"Friday",@"Saturday",@"Sunday"]; .
-
} .
-
-(void)cofigureTableview
-
{
-
self.table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
-
self.table.delegate = self;
-
self.table.dataSource = self;
-
[self.view addSubview:self.table]; .
-
} .
-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-
return 1;
-
}
-
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-
{
-
return _content.count;
-
} .
-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-
{
-
static NSString *cellIdentifier = @"cellIdentifier"; .
-
UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:cellIdentifier]; .
-
if(cell == nil) {
-
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; .
-
}
-
cell.textLabel.text = [_content objectAtIndex:indexPath.row];
-
return cell;
-
} .
-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
-
{
-
NSLog(@"title of cell %@", [_content objectAtIndex:indexPath.row]);
-
}