Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. arr = [NSArray arrayWithObjects:@"aaa", @"bbb", @"ccc", @"ddd", @"eee", @"fff", nil];
  5. myTableView = [[UITableView alloc]initWithFrame:CGRectMake(20, 130, 280, 220)];
  6. [myTableView registerClass:[CustomCell class] forCellReuseIdentifier:@"Cell"];
  7. myTableView.delegate = self;
  8. myTableView.dataSource = self;
  9. [self.view addSubview:myTableView];
  10. }
  11.  
  12. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  13. {
  14. static NSString* cellIdentifier = @"Cell";
  15. CustomCell* cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  16. if (cell == nil) {
  17. cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  18. }
  19. cell.customLabel.text = [arr objectAtIndex:indexPath.row];
  20. return cell;
  21. }
  22.  
  23. - (id)init{
  24. self = [super init];
  25. if (self){
  26. self.backgroundColor = [UIColor redColor];
  27. //But in ViewController, cell is not red.
  28. }
  29. return self;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement