У меня большая проблема с UITableView, я хочу использовать метку внутри ячейки, поэтому я использую этот метод для этого
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ItemCell";
// If the indexPath is less than the numberOfItemsToDisplay, configure and return a normal cell,
// otherwise, replace it with a button cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
else {
}
if (indexPath.section == 0) {
elemento = [array objectAtIndex:indexPath.row];
UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 220, 30)];
labelTitle.text = [elemento objectForKey:@"Titolo"];
labelTitle.backgroundColor = [UIColor clearColor];
labelTitle.textColor = [UIColor whiteColor];
[cell addSubview:labelTitle];
} else {
UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 220, 30)];
labelTitle.text = @"Read More";
labelTitle.backgroundColor = [UIColor clearColor];
labelTitle.textColor = [UIColor whiteColor];
[cell addSubview:labelTitle];
}
return cell;
}
таким образом я могу видеть все данные в моей таблице, но метка перекрывается, чем я пытаюсь использовать этот метод
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ItemCell";
// If the indexPath is less than the numberOfItemsToDisplay, configure and return a normal cell,
// otherwise, replace it with a button cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
if (indexPath.section == 0) {
elemento = [array objectAtIndex:indexPath.row];
UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 220, 30)];
labelTitle.text = [elemento objectForKey:@"Titolo"];
labelTitle.backgroundColor = [UIColor clearColor];
labelTitle.textColor = [UIColor whiteColor];
[cell addSubview:labelTitle];
} else {
UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 220, 30)];
labelTitle.text = @"Read More";
labelTitle.backgroundColor = [UIColor clearColor];
labelTitle.textColor = [UIColor whiteColor];
[cell addSubview:labelTitle];
}
}
else {
}
return cell;
}
метка в порядке, но в этом случае я вижу на своей таблице только 5 данных, и эти 5 данных повторяются в течение некоторого времени ...
Например, если в первом случае на моей таблице я вижу: 1,2,3,4,5,6,7,8,9,10, ...
во втором случае я вижу: 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5, ...
в чем проблема?