Reputation: 4301
Im totally unsure why my accessory view is not working. I simply want some text to appear to the right of the UITableViewCell (as well as the left), but only the text on the left is displaying.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"];
if (cell==nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SwitchCell"] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 60, 30)];
cell.textLabel.text = @"left text";
label.text = @"right text";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryView = label;
[label release];
}
return cell;
}
Any ideas? Thanks.
Upvotes: 8
Views: 24886
Reputation: 548
Also remember: accessoryType property is ignored if you have custom accessoryView. So, this line of code is excess.
Upvotes: 0
Reputation: 149
UITableViewCellStyleValue2 gives me a weird style. I think the most commonly requested style is UITableViewCellStyleValue1 (at least for my case).
Upvotes: 0
Reputation: 11546
cell.accessoryView = label;
You are setting your accessoryView to be a label so you're not going to see any disclosure indicator. If you want title and detail text in your cell then init it with UITableViewCellStyleValue2 like this...
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cellType"] autorelease];
...and then set the title and detail like this...
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"Description";
To get an idea of the different built in table styles check the following image...
You can adjust the textLabel and detailTextLabel to suit your taste.
Upvotes: 26
Reputation: 7386
-(id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
was depreciated in iOS 3.0
Instead use:
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
Pass in either UITableViewCellStyleValue1
or UITableViewCellStyleValue2
and set the textLabel
and detailTextLabel
properties as you need.
Upvotes: 3
Reputation: 49047
Why this? You can't have both.
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Upvotes: 6