Monday 28 September 2015

How To Use Custom Cell In UITableViewCell In UITableView Ios/Iphone

==> First Create File Of Inherited From UItableViewCell:
 
@interface CustomCell : UITableViewCell
{
   
}

@property (weak, nonatomic) IBOutlet UIImageView *imgViewThumb;
@property (weak, nonatomic) IBOutlet UILabel *lblName;

@property (nonatomic, strong) NSIndexPath *indexPath;

- (IBAction)btnTapped:(UIButton *)sender;

@end

-------------------------------

#import "CustomCell.h"

@implementation CustomCell

- (void)awakeFromNib {
    // Initialization code
}

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

    // Configure the view for the selected state
}

- (IBAction)btnTapped:(UIButton *)sender
{
    NSLog(@"Button clicked for row at index :%lu", self.indexPath.row);
}

@end

---------------------This Custom Cell Use MainView Controller In Where Used UITableView As CellForRowtAtIndexpath  IN Delegete Method-
:
                                 ==>  Data Sources Method: UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *aTblCell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:@"CellOne" forIndexPath:indexPath];
    aTblCell.indexPath = indexPath;
   
    NSDictionary *aDictStudInfo = (NSDictionary *) [mutArrStudents objectAtIndex:indexPath.row];
   
    if(indexPath.row % 2 == 0)
    {
        aTblCell.imgViewThumb.image = [UIImage imageNamed:@"a.png"];
    }
    else
    {
        aTblCell.imgViewThumb.image = [UIImage imageNamed:@"b.png"];
    }
   
    //aTblCell.lblName.text = [NSString stringWithFormat:@"ROW NUMBER :%lu", indexPath.row];
    aTblCell.lblName.text = [aDictStudInfo objectForKey:@"name"];
   
    return aTblCell;
}

                                 ==>  Delegate Method: UITableView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *aDictStudentInfo = (NSDictionary *) [mutArrStudents objectAtIndex:indexPath.row];
    NSLog(@"%@", aDictStudentInfo);
    [self performSegueWithIdentifier:@"showDetail" sender:aDictStudentInfo];
}