我正在尝试开发一种使最喜欢的收藏夹完美运行的功能,但是当我按下下一个或上一个按钮时,它会崩溃...
我不知道如何检查 FavouriteArray 中是否存在当前消息..?if is Exist Then FavouriteButton images 更改为 Favourite-ON.png 否则其图像 Favourite-OFF.png..
我的代码在下面===================
// Adding Current Message to Favourite Array
- (IBAction)FavouritebtnClick:(id)sender //Favourite Button Work Perfectly
{
Make_Fav_Text = [NSString stringWithFormat:@"%@",[[[TabBarTutorialAppDelegate shareDelegate].level_array valueForKey:@"SMS"] objectAtIndex:row_no]];
NSLog(@"Make Favourite TExt====%@",Make_Fav_Text);
[DatabaseFiles InsertFav:[NSString stringWithFormat:@"%@",Make_Fav_Text]];//insert to database
[FavouriteBtnChange setImage:[UIImage imageNamed:@"FAv_On-iphone.png"] forState:UIControlStateNormal];
}
// 检查当前消息在 FavouriteArray 中是否可用
-(void)Check_Fav_Available
{
for (NSString *Myfav in Check_Fav_Avail)
{
NSLog(@"MYFAV===%@",Myfav);
if ([Myfav isEqual:sms.text])
{
[FavouriteBtnChange setImage:[UIImage imageNamed:@"FAv_On-iphone.png"] forState:UIControlStateNormal];
NSLog(@"Found Favourite");
//break;
}
else{
NSLog(@"NOt Found");
[FavouriteBtnChange setImage:[UIImage imageNamed:@"FAv_On-copy-iphone"] forState:UIControlStateNormal];
}
}
}
//Next Button
- (IBAction)Nextbtn:(id)sender
{
row_no=row_no+1;
lblno=row_no;
lblno=lblno+1;
[self Check_Fav_Available]; //Check Current Message in Favourite Array;
if (row_no==[TabBarTutorialAppDelegate shareDelegate].level_array.count)
{
row_no=row_no-1;
// lblno=lblno-1;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"This is last SMS" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
NSLog(@"this is last");
NSLog(@"row no is %d",row_no);
}
else
{
if (row_no <=4)
{
sms.text=[[[TabBarTutorialAppDelegate shareDelegate].level_array objectAtIndex:row_no] objectForKey:@"SMS"];
NSString *str = [NSString stringWithFormat:@"%d - %d",lblno,[TabBarTutorialAppDelegate shareDelegate].level_array.count];
no_lbl.text=str;
NSLog(@"row no is %d",row_no);
[self Check_Fav_Available];
}
else
{
UIAlertView *Purchasealert = [[UIAlertView alloc] initWithTitle:@"Purchase Category" message:@"Purchase to Enjoy More" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Buy Message", nil];
Purchasealert.tag=1710;
[Purchasealert show];
[self gostore];
NSLog(@"this is last");
NSLog(@"row no is %d",row_no);
}
}
}
//Previous Button
- (IBAction)Previousbtn:(id)sender
{
//[FavouriteBtnChange setImage:[UIImage imageNamed:@"FAv_On-copy-iphone.png"] forState:UIControlStateNormal];
row_no=row_no-1;
lblno=lblno-1;
if (row_no<0)
{
row_no=row_no+1;
lblno=lblno+1;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"This is First SMS" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
NSLog(@"this is last");
}
else
{
[self Check_Fav_Available]; //Check Favourite available
sms.text=[[[TabBarTutorialAppDelegate shareDelegate].level_array objectAtIndex:row_no] objectForKey:@"SMS"];
NSString *str = [NSString stringWithFormat:@"%d - %d",lblno,[TabBarTutorialAppDelegate shareDelegate].level_array.count];
no_lbl.text=str;
[self Check_Fav_Available];
NSLog(@"arr is %d",[TabBarTutorialAppDelegate shareDelegate].level_array.count);
NSLog(@"row no is %d",row_no);
}
}