Can I customize the width of a UITableViewCell?

I would like to know if the width of a UITableViewCell can be adjusted. I would like to put an image to the left of it (for example, the type of contact in the address book). I found a post here that provides a picture of exactly what I'm trying to accomplish. I would also like to confirm the answers to this post.

+2
source share
3 answers

OS3.0 has some style options in the API that can do what you want.

Or you can create a fully customizable table view cell in Interface Builder, for example, in one of my applications that I make in my ForRowAtIndexPath cell:

PlaceViewCell *cell = (PlaceViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [self createNewPlaceCellFromNib];
}

And this is the method to dig it out of the NIB

- (PlaceViewCell*) createNewPlaceCellFromNib {
    NSArray* nibContents = [[NSBundle mainBundle]
                            loadNibNamed:@"PlaceCell" owner:self options:nil];
    NSEnumerator *nibEnumerator = [nibContents objectEnumerator];
    PlaceViewCell* placeCell = nil;
    NSObject* nibItem = nil;
    while ( (nibItem = [nibEnumerator nextObject]) != nil) {
        if ( [nibItem isKindOfClass: [PlaceViewCell class]]) {
            placeCell = (PlaceViewCell*) nibItem;
            if ([placeCell.reuseIdentifier isEqualToString: @"Place" ]) {
                //NSLog(@"PlaceCell - we have a winner!");
                break; // we have a winner
            } else {
                placeCell = nil;
                NSLog(@"PlaceCell is nil!");
            }
        }
    }
    return placeCell;
}

UITableViewCell Interface Builder.

+2

IMO UITableViewCell, , , . Apple , ( , ).

UITableViewCellStyle:

  • UITableViewCellStyleDefault
  • UITableViewCellStyleSubtitle
  • UITableViewCellStyleValue1
  • UITableViewCellStyleValue2

UITableViewCell, TableView Connection Apple:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSDictionary *item = (NSDictionary *)[self.content objectAtIndex:indexPath.row];
    cell.textLabel.text = [item objectForKey:@"mainTitleKey"];
    cell.detailTextLabel.text = [item objectForKey:@"secondaryTitleKey"];
    NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"imageKey"] ofType:@"png"];
    UIImage *theImage = [UIImage imageWithContentsOfFile:path];
    cell.imageView.image = theImage;
    return cell;
}
0

You do not need to change the width of the cell. What you really need is to make the cell look like a different width (for example, by changing the width of the visible subset).

Unfortunately, your link does not work, so I cannot be more specific.

You can also try using the method tableView:indentationLevelForRowAtIndexPath:in the protocol UITableViewDelegate.

0
source

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


All Articles