Skip to content

TableView Objective c 0

Azmal Tech edited this page Dec 27, 2016 · 2 revisions
  1. @interface ViewController () <UITableViewDelegate,UITableViewDataSource> .

  2. @property (strong,nonatomic) UITableView *table;

  3. @property (strong,nonatomic) NSArray *content; . .

  4. @end .

  5. @implementation ViewController .

  6. - (void)viewDidLoad {

  7. [super viewDidLoad];

  8. [self cofigureTableview];

  9. self.content = @[ @"Monday", @"Tuesday", @"Wednesday",@"Thursday",@"Friday",@"Saturday",@"Sunday"]; .

  10. } .

  11. -(void)cofigureTableview

  12. {

  13. self.table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

  14. self.table.delegate = self;

  15. self.table.dataSource = self;

  16. [self.view addSubview:self.table]; .

  17. } .

  18. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

  19. return 1;

  20. }

  21. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

  22. {

  23. return _content.count;

  24. } .

  25. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

  26. {

  27. static NSString *cellIdentifier = @"cellIdentifier"; .

  28. UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:cellIdentifier]; .

  29. if(cell == nil) {

  30. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; .

  31. }

  32. cell.textLabel.text = [_content objectAtIndex:indexPath.row];

  33. return cell;

  34. } .

  35. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

  36. {

  37. NSLog(@"title of cell %@", [_content objectAtIndex:indexPath.row]);

  38. }

Clone this wiki locally