February 2012
Intermediate to advanced
872 pages
22h 43m
English
You want to grab users’ attention in a table view by displaying accessories, and offer different ways to interact with each cell in your table view.
Use the accessoryType of the
UITableViewCell
class, instances of which you provide to your table view in its data
source object:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell* result = nil; if ([tableView isEqual:self.myTableView]){ static NSString *MyCellIdentifier = @"SimpleCell"; /* We will try to retrieve an existing cell with the given identifier */ result = [tableView dequeueReusableCellWithIdentifier:MyCellIdentifier]; if (result == nil){ /* If a cell with the given identifier does not exist, we will create the cell with the identifier and hand it to the table view */ result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier]; } result.textLabel.text = [NSString stringWithFormat:@"Section %ld, Cell %ld", (long)indexPath.section, (long)indexPath.row]; result.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; } return result; } - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10; } - (void)viewDidLoad{ [super viewDidLoad]; self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; self.myTableView.dataSource = self; self.myTableView.delegate ...Read now
Unlock full access