Я написал некоторую логику в методе cellForRowAtIndexpath
в UITableview
. Когда я быстро прокручиваю UITableView
, метод не вызван.Метод cellForRowAtIndexpath не вызывается, когда я быстро прокручиваю таблицу
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
@try
{
NSLog(@"Cell no :%d",indexPath.row);
if(requestMode)
{
NSLog(@"Request mode.");
AlertBoxCell *cell=(AlertBoxCell *)[tableView dequeueReusableCellWithIdentifier:@"InboxCell"];
if(cell==nil)
cell=[[NSBundle mainBundle] loadNibNamed:@"AlertBoxCell" owner:self options:nil][0];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UIView* bgview = [[UIView alloc] init];
bgview.backgroundColor=[UIColor clearColor];
UIView* bgview1 = [[UIView alloc] initWithFrame:CGRectMake(-2, -5, 235, 109)];
slider=[self getSlider];
BOOL emergencyType; // For show acceptedby info only for normal accepted alerts
if ([alertCode[indexPath.row] isEqualToString:@"ALERT_EMERGENCY"]||[alertCode[indexPath.row] isEqualToString:@"HELP_EMERGENCY"])
{
cell.messageLabel.font=[UIFont fontWithName:@"MyriadPro-Bold" size:25];
NSMutableAttributedString *resultString;
if(![senderName[indexPath.row] isEqualToString:@"NA"])
{
NSMutableAttributedString * content2 = [[NSMutableAttributedString alloc] initWithString:senderName[indexPath.row] attributes:@{NSFontAttributeName: [UIFont fontWithName:@"MyriadPro-Bold" size:25]}];
NSMutableAttributedString * content3 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n%@",allAlerts[indexPath.row]] attributes:@{NSFontAttributeName: [UIFont fontWithName:@"MyriadPro-Regular" size:20]}];
resultString = [content2 mutableCopy];
[resultString appendAttributedString:content3];
}
else
{
NSMutableAttributedString* content3 = [[NSMutableAttributedString alloc] initWithString:allAlerts[indexPath.row] attributes:@{NSFontAttributeName: [UIFont fontWithName:@"MyriadPro-Regular" size:20] }];
resultString = [content3 mutableCopy];
}
cell.messageLabel.attributedText=resultString;
emergencyType=YES;
bgview1.layer.contents=(id)[[UIImage imageNamed:@"blue_alert.png"]CGImage];
if([allAlertStatus[indexPath.row] isEqualToString:@"1"])
{
slider.value=0.0;
slider.userInteractionEnabled=NO;
}
else
slider.value=1.1;
}
else
{
/*
@"FranklinGothDemiCTT"
@"MyriadPro-Bold"
@"MyriadPro-Regular"
@"MyriadPro-Cond"
FranklinGothBookCTT
*/
cell.messageLabel.font=[UIFont fontWithName:@"MyriadPro-Bold" size:20];
//[cell.messageLabel setFrame:CGRectMake(30, 7, 198, 88)];
cell.messageLabel.text=allAlerts[indexPath.row];
emergencyType=NO;
if([allAlertStatus[indexPath.row] isEqualToString:@"1"])
{
bgview1.layer.contents=(id)[[UIImage imageNamed:@"yellow_alert.png"]CGImage];//yellow color
slider.value=0.0;
slider.userInteractionEnabled=NO;
}
else
{
bgview1.layer.contents=(id)[[UIImage imageNamed:@"red_alert.png"]CGImage];
slider.value=1.0;
}
if([clearIds[indexPath.row] isEqualToString:@"1"])
{
bgview1.backgroundColor =[UIColor greenColor];
slider.value=0.0;
slider.userInteractionEnabled=NO;
}
}
cell.layer.masksToBounds=YES;
cell.textLabel.backgroundColor=[UIColor clearColor];
[bgview addSubview:bgview1];
[cell setBackgroundView:bgview];
/**shows who accept the alert*/
if(![allAlertStatus[indexPath.row] isEqualToString:@"1"])
{
UIButton *b1=[UIButton buttonWithType:UIButtonTypeCustom];
b1.frame=CGRectMake(237, 32.5, 75, 35);
[b1 setImage:[UIImage
imageNamed:@"background_switch_button.png"]
forState:UIControlStateNormal];
[b1 setUserInteractionEnabled:NO];
b1.tag=indexPath.row+10;
[cell addSubview:b1];
slider.tag=indexPath.row+10;
[cell addSubview:slider];
}
else
{
if(!emergencyType)
{
NSString *str=[NSString stringWithFormat:@"Accepted by:\n%@",acceptedUserNames[indexPath.row]];
if([str length]>32)
str=[[str substringToIndex:32] stringByAppendingString:@"..."];
else if([str length]<25)
str=[str stringByAppendingString:@" "];
UIImageView *tickImage=[[UIImageView alloc]initWithFrame:CGRectMake(258, 18, 35, 20)];
[tickImage setImage:[UIImage imageNamed:@"checkMark.png"]];
[cell addSubview:tickImage];
UILabel *tempLabel=[GlobalDesign createLabel:str fontFamilyName:@"FranklinGothDemiCTT" fontColor:[UIColor colorWithRed:195/255.0 green:47/255.0 blue:52/255.0 alpha:1] fontSize:15 xVal:233 yVal:45 width:85 height:50];
[cell addSubview:tempLabel];
tempLabel.lineBreakMode=NSLineBreakByTruncatingTail;
NSMutableAttributedString* content2 = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName: [UIFont fontWithName:@"FranklinGothDemiCTT" size:18] }];
[content2 setAttributes: @{ NSFontAttributeName:[UIFont fontWithName:@"FranklinGothBookCTT" size:15]} range:NSMakeRange(0,12)];
tempLabel.attributedText=content2;
}
else
{
UIButton *b1=[UIButton buttonWithType:UIButtonTypeCustom];
b1.frame=CGRectMake(240, 32.5, 75, 35);
[b1 setImage:[UIImage
imageNamed:@"ACCEPTED.png"]
forState:UIControlStateNormal];
[b1 setUserInteractionEnabled:NO];
b1.tag=100;
[cell addSubview:b1];
[cell addSubview:slider];
}
}
if(indexPath.row==noOfRows-1)
{
requestMode=NO;
NSLog(@"Final values in array %d",[updatedCell count]);
}
NSLog(@"Added to array :%d",indexPath.row);
[updatedCell addObject:cell];
NSLog(@"Final values in array %d",[updatedCell count]);
return cell;
}
else
{
NSLog(@"Refresh mode mode. %d",indexPath.row);
if(updatedCell[indexPath.row]!=nil)
return updatedCell[indexPath.row];
else {
AlertBoxCell *cell=(AlertBoxCell *)[tableView dequeueReusableCellWithIdentifier:@"InboxCell"];
if(cell==nil)
cell=[[NSBundle mainBundle] loadNibNamed:@"AlertBoxCell" owner:self options:nil][0];
return cell;
}
}
}
@catch (NSException *exception)
{
NSLog(@"Exception :%@",exception);
[[WriteLogger getWriteLogger] writeLog:moduleName sourceClass:self.nibName methodName:@"cellForRowAtIndexPath" errorMsg:exception];
}
}
В приведенном выше коде, например, номер ячейки: от 1 до 45 печатается при прокрутке. После этого будет вызвано 52. Есть ли у вас какие-либо идеи?
Может быть, он будет двигаться, чтобы поймать. – sathiamoorthy
NSLog в блоке catch, который не печатается ... –
Просто любопытно: почему вы используете предложение try/catch? В вашем сценарии это может быть вредно. – CouchDeveloper