我試圖開發出Funcationality,使收藏夾 最喜歡的是工作完美的,但是當我按一個或下一個按鈕它崩潰了...如何檢查NsmutableArray中可用的當前字符串..?
我不知道如何來檢查當前的消息是存在於FavouriteArray .. ? if is Exist Then FavouriteButton images更改爲Favorite-ON.png,否則爲其圖像Favorite-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);
}
}
什麼是Crash Exception ..? –
使用'isEqualToString'與字符串綁定在數組中或不使用isEqual –
@kumarKI:***終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [NSConcreteMutableAttributedString countByEnumeratingWithState:objects:count:]:無法識別的選擇器發送到實例0xaa62e90' ***第一次拋出調用堆棧: – Saytovishal