11 Jan 2017

DynamicCells (TVcell Class & viewController ) Full Code...


 DynamicCells (TVcell Class & viewController )......



Do Some AutoLayouts as Shown in Below LINK then Code will Works......




@interface TableViewCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailsLabel;


@end

@implementation TableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end



@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UITableView *tableView;

@property NSArray *titleArray;
@property NSArray *detailsArray;

@end



#import "ViewController.h"
#import "TableViewCell.h"

@interface ViewController ()

@end

@implementation ViewController

- (void) viewDidAppear:(BOOL)animated {
    [_tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    _titleArray = [[NSArray alloc]initWithObjects:
                   @"Apple",
                   @"ios",
                   @"thrymr",
                   @"kapiltowers",
                   nil];
    _detailsArray = [[NSArray alloc]initWithObjects:
                     @"If you test the app, the cell is still not resized. The reason is that both name and address labels are set to 1-line. So set the number of lines to zero and let the label grow automatically.",
                     @"tableView.estimatedRowHeight = 44.0 tableView.rowHeight = UITableViewAutomaticDimension.",
                     @"Self Sizing Cell is particularly useful to support Dynamic Type.",
                     @"However, without auto layout, self sizing cells won’t work as it relies on the constraints to determine the proper row height.",
                     nil];
    
    _tableView.estimatedRowHeight = 100.0;
    _tableView.rowHeight = UITableViewAutomaticDimension;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [_titleArray count];
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellid=@"cell";
    TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
    }
    NSString *tempStr = [_titleArray objectAtIndex:indexPath.row];
    cell.titleLabel.text  = tempStr;
    NSString *deatalsStr = [_detailsArray objectAtIndex:indexPath.row];
    cell.detailsLabel.text = deatalsStr;
    
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0