This one basically is needed on almost every application that you build on iphone. In one way or another, you need to write your custom table view cell classes. For example if you want to have a table view with images on the left and text on the right you need to overwrite UITableViewCell. Good thing is; it is not that difficult. Here are the steps:
- First create a new View XIB file from your interface builder named it as X.
- Then remove the view and put a UITableViewCell to your UI.
- Now you need to click on your UITableViewCell element and change it class to to X from your interface builder.
- Now double click yo your custom table view cell and put some labels image views etc on your need.
- Now wire all elements in your IB by defining them in your .m file and referencing them as outlets in your IB.
- You are ready to go. In your Table View you just need to replace the standart UITableViewCell object by a new Custom Table View Cell X by the following code
static NSString *CellIdentifier = @"X";
X *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"X" owner:self options:nil];
for(id currentObject in topLevelObjects) {
if([currentObject isKindOfClass:[X class]]) {
cell = (X *)currentObject; break;
}
}
//configure your cell
return cell;
}
No comments:
Post a Comment