订单管理那个cell 加了个红色label。
但是一开始显示不出来,滑动tableview,重新刷新一下,才显示
如图:
代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"tableViewCell" ;
UITableViewCell *result ;
result = [tableView dequeueReusableCellWithIdentifier:identifier];
if (result == nil) {
result = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
else{
while ([result.contentView.subviews lastObject] != nil) {
[[result.contentView.subviews lastObject] removeFromSuperview];
}
}
if ([result.textLabel.text isEqualToString:@"订单管理"]){
UILabel *newMsgLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
newMsgLabel.center = CGPointMake(result.vRightPos - 70, result.vHeight/2);
newMsgLabel.text = @"1 ";
[newMsgLabel sizeToFit];
newMsgLabel.textColor = WHITE_COLOR;
newMsgLabel.textAlignment = NSTextAlignmentCenter;
newMsgLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
newMsgLabel.font = TF_FONT_LEVEL_1;
newMsgLabel.backgroundColor = RED_COLOR;
newMsgLabel.layer.cornerRadius = newMsgLabel.vHeight/2;
newMsgLabel.clipsToBounds = YES;
[result.contentView addSubview:newMsgLabel];
}
}
빨간 점으로 표시된 셀에 대해서는 별도의 클래스를 정의하고, 컨트롤러에서는 뷰 코드를 만들지 않는 것이 좋을 것 같습니다.
tableviewCell을 사용자 정의하는 방법은 다음 블로그를 참조하세요: http://www.hcios.com/archives/460
이 빨간색 점을 미리 추가해 두는 것이 좋습니다. 그런 다음 cellForRowAtIndexPath에서 표시 및 숨기기를 제어합니다.
result.textLabel.text에 값을 어디에 할당했나요? [result.textLabel.text isEqualToString:@"Order Management"] 실행 전, 주신 코드에는 할당 작업이 보이지 않아 할당 및 판단 순서가 잘못되어 발생한 것으로 추측됩니다.