2013-04-27 6 views
-3

При нажатии на ячейку ярлык, который был добавлен в ячейку, похож на прилагаемый рисунок, почему это ???UILabel on UITableViewCell

http://s23.postimg.org/x4a7ffd7v/Untitled.png

это код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{
статический NSString * CellIdentifier = @ "Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

int section = [indexPath section]; 
int row = [indexPath row]; 

int rowsInLastSections = 0; 
for (int i = 0; i < section; i++) { 
    rowsInLastSections += [self tableView:tableView numberOfRowsInSection:i]; 
} 

Friend *friend = [friendsArray objectAtIndex:row + rowsInLastSections]; 

[friend setIndexPathInTableView:indexPath]; 

NSString *firstName = [[NSString alloc]initWithFormat:@"%@", [friend firstName]]; 
NSString *lastName = [[NSString alloc]initWithFormat:@"%@", [friend lastName]]; 

UIImageView *profileImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 50, 50)]; 
[profileImageView setImageWithURL:[NSURL URLWithString:[friend imageUrl]] placeholderImage:[UIImage imageNamed:@"[email protected]"]]; 

UILabel *firstNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(65, 10, 230, 20)]; 
UILabel *lastNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(65, 35, 230, 20)]; 
[firstNameLabel setText:firstName]; 
firstNameLabel.backgroundColor = table.backgroundColor; 
[lastNameLabel setText:lastName]; 
lastNameLabel.backgroundColor = table.backgroundColor; 

[cell.contentView addSubview:profileImageView]; 
[cell.contentView addSubview:firstNameLabel]; 
[cell.contentView addSubview:lastNameLabel]; 

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
[cell setSelectionStyle:UITableViewCellSelectionStyleGray]; 

return cell; 

}

+0

Просьба предоставить более подробную информацию. Некоторый код будет отличным ... – atxe

+3

Вы должны опубликовать свой код для различных методов 'UITableViewDelegate' и' UITableViewDataSource'. – jszumski

+0

Этот код для добавления subviews в ячейку:: http: //pastie.org/7729414 – assafey

ответ

1

после

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

добавить этот код,

for(UIView *view in cell.subviews){ 
     if([view isMemberOfClass:[UILabel class]]){ 
      [(UILabel *)view removeFromSuperview]; 
     } 
    } 
+0

«В первую очередь я должен сказать, как вы это делаете, это нехорошо». Как мне это сделать? – assafey

+0

Я не добавляю uilabels или любой другой компонент в метод didSelectRowAtIndexPath – assafey

+0

Я изменил ответ в соответствии с вашим кодом, пожалуйста, проверьте новый ответ. –

Смежные вопросы