UITableViewCell accessoriesView not showing

I absolutely do not know why my accessory does not work. I just want some text to display to the right of the UITableViewCell (and also to the left), but only the text to the left is displayed.

- (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.

+6
source share
5 answers
 cell.accessoryView = label; 

You set your accessory as a shortcut so that you do not see the disclosure indicator. If you want to get the header text and details in your cell, then run it using UITableViewCellStyleValue2, like this ...

 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cellType"] autorelease]; 

... and then set the title and details like this ...

 cell.textLabel.text = @"Title"; cell.detailTextLabel.text = @"Description"; 

To get an idea of ​​the different built-in table styles, check out the following image ...

enter image description here

You can customize textLabel and detailTextLabel to suit your taste.

+24
source

Why is this? You cannot have both.

 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
+6
source
 -(id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier 

depreciated in iOS 3.0

Use instead:

 -(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 

Pass either UITableViewCellStyleValue1 or UITableViewCellStyleValue2 and set the textLabel and detailTextLabel properties as you need.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html%23//apple_ref/doc/uid/TP40006938-CH3-SW34

+3
source

UITableViewCellStyleValue2 gives me a weird style. I think the most frequently requested style is UITableViewCellStyleValue1 (at least for my case).

0
source

Also remember: propertyType is ignored if you have a custom accessory. So this line of code is redundant.

0
source

Source: https://habr.com/ru/post/890498/


All Articles