- #define kCustomCellIdentifier @"customCellId"
- @implementation CustomCell
- + (id)cell {
- CustomCell *cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCustomCellIdentifier];
- return cell;
- }
- + (id)cellForTableView:(UITableView *)tableView
- {
- CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:kCustomCellIdentifier];
- if (!cell) {
- cell = [self cell];
- }
- return cell;
- }
- // ...
You can call the above code like this:
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CustomCell *cell = [CustomCell cellForTableView:tableView];
- // ...
This is useful to simplify the tableView dataSource codes.