int indx;
我在头文件中声明了该属性。然后在实现文件中我有这两种方法:
-(IBAction)nextHaiku
{
{
if (!self.indx)
{
self.indx=0;
}
NSString *cat = self.selectedCategory;
//For now (adjust later so that, according to UISegmentedControl, it will also show only the user's haiku or all haiku):
cat = @"Derfner";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category == %@", cat];
NSArray *filteredArray = [self.gayHaiku filteredArrayUsingPredicate:predicate];
int array_tot = [filteredArray count];
int sortingHat;
if (array_tot > 0)
if (self.indx == self.theseAreDone.count)
{
while (true)
{
sortingHat = (arc4random() % array_tot);
if (![theseAreDone containsObject:[filteredArray objectAtIndex:sortingHat]]) break;
}
self.haiku_text.text = [[filteredArray objectAtIndex:sortingHat] valueForKey:@"quote"];
if (!self.theseAreDone || self.theseAreDone.count==array_tot)
{
self.theseAreDone = [[NSMutableArray alloc] init];
}
[theseAreDone addObject:[filteredArray objectAtIndex:sortingHat]];
self.indx = self.theseAreDone.count;
}
else
{
self.haiku_text.text = [[self.theseAreDone objectAtIndex:indx] valueForKey:@"quote"];
self.indx += self.indx;
}
}
}
和
-(IBAction)previousHaiku
{
self.haiku_text.text = [[self.theseAreDone objectAtIndex:self.indx-1] valueForKey:@"quote"];
self.indx -= self.indx;
}
NSLog
表明每次调用self.indx
递增 1 。newHaiku
而且NSLog
还说明self.indx
从previousHaiku
0开始,不管它是什么最后一次newHaiku
被调用。
我错过了什么?