Custom UITableViewCell

How can I set up a UITableviewCell since I want to see the label, date and image in one cell.

+3
source share
4 answers

Take a look at this link.

Here you will learn how to create a custom cell using Interface Builder and use it in Xcode for your application.

http://www.e-string.com/content/custom-uitableviewcells-interface-builder

+1
source

( ). UITableViewCell ( , ). , , . , :

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        // notice the Style. The UITableViewCell has a few very good styles that make your cells look very good with little effort
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    // In my case I get the data from the elements array that has a bunch on dictionaries
    NSDictionary *d = [elements objectAtIndex:indexPath.row];

    // the textLabel is the main label
    cell.textLabel.text = [d objectForKey:@"title"];

    // the detailTextLabel is the subtitle
    cell.detailTextLabel.text = [d objectForKey:@"date"];

    // Set the image on the cell. In this case I load an image from the bundle
    cell.imageView.image = [UIImage imageNamed:@"fsaint.png"];

    return cell;
}
+3

UITableViewCell Interface Builder Code

+2

UITableViewCell self.contentView. , .

, , 3 :

@property(nonatomic, retain) UIImage *userPic;
@property(nonatomic, retain) NSString *label;
@property(nonatomic, retain) NSString *date;

(drawRect:):

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    [userPic drawInRect: CGRectMake(10, 5, 50, 50)];
    [label drawAtPoint:CGPointMake(70, 5) withFont:[UIFont boldSystemFontOfSize:17]];
    [date drawAtPoint:CGPointMake(70, 30) withFont:[UIFont systemFontOfSize:14]];
  }

For more examples, try checking out this structure that uses this style: https://github.com/andrewzimmer906/XCell

0
source

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


All Articles