Reputation: 169
Im trying to make a custom label instead of the standard textabel and detailtextlabel.
i've tried doing this by creating a label called "labelNumb", but it wont print it in the cells how come and how can i position this label in the cell?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.userInteractionEnabled = NO;
UILabel *labelNumb = [[UILabel alloc] init];
[cell.contentView addSubview:labelNumb];
labelNumb.text = [NSString stringWithFormat:@"%@",[scoreArray2 objectAtIndex:indexPath.row]];
return cell;
}
Upvotes: 0
Views: 55
Reputation: 1472
cell
is nil, and if it is create a new UITableViewCell
with the same identifier
. UILabel
to it, and pass it in the
addSubview:
method.Upvotes: 0
Reputation: 66302
You haven't set the frame for labelNumb
.
Also, if (cell == nil)
will never happen since dequeueReusableCellWithIdentifier:forIndexPath:
is guaranteed to return a cell.
Also, this will mess up as you start scrolling, since you're adding a new UILabel every time, instead of reusing the existing one.
Upvotes: 1