// must set delegate & dataSource, otherwise the the table will be empty and not responsive tableView.delegate = self; tableView.dataSource = self;
tableView.backgroundColor = [UIColor cyanColor];
// add to canvas [self.view addSubview:tableView]; }
#pragma mark - UITableViewDataSource // number of section(s), now I assume there is only 1 section - (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView { return1; }
// number of row in the section, I assume there is only 1 row - (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section { return1; }
// the cell will be returned to the tableView - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { staticNSString *cellIdentifier = @"HistoryCell"; // Similar to UITableViewCell, but JSCustomCell *cell = (JSCustomCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[JSCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } // Just want to test, so I hardcode the data cell.descriptionLabel.text = @"Testing"; return cell; }
#pragma mark - UITableViewDelegate // when user tap the row, what action you want to perform - (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"selected %d row", indexPath.row); }
@end
Simple? Basically is all the same, the only different is you have to configure those controls programmatically.