UITableView Data Source & Delegate Template

#pragma mark - View Cycle - (id)initWithTableView:(UITableView*)tableView{ self = [super init]; if(self){ _tableView = tableView; _tableView.delegate = self; _tableView.dataSource = self; _tableViewData = @[]; } return self; } - (void)setTableViewData:(NSArray *)tableViewData{ _tableViewData = tableViewData; [_tableView reloadData]; } #pragma mark - UITableView Delegate & Data Source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _tableViewData.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; if(_cellSelectedBlock) _cellSelectedBlock(); }
This is a template for a UITableView Data Source and Delegate file. It may vary depending on your desired UITableView behaviour.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.