0

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.indxpreviousHaiku0开始,不管它是什么最后一次newHaiku被调用。

我错过了什么?

4

1 回答 1

0

我缺少的是我是个白痴的事实。我正在使用self.indx -= self.indx而不是self.indx -=1. 不要问我为什么。我不能告诉你。

于 2012-08-10T22:27:10.917 回答