UITextView不会更新

时间:2011-04-07 19:26:11

标签: iphone ios4 uitextview

我正在尝试以编程方式更新UITextView的文本。这是几天前的工作,但不知道为什么它已经停止。

创建UITextView

self.recordInfoTextView = [[UITextView alloc] initWithFrame:textFrame];    
self.recordInfoTextView.editable=NO;
self.recordInfoTextView.scrollEnabled=NO;
self.recordInfoTextView.multipleTouchEnabled=NO;
self.recordInfoTextView.userInteractionEnabled=NO;  
self.recordInfoTextView.textAlignment=UITextAlignmentCenter;
self.recordInfoTextView.font=[UIFont systemFontOfSize:12.0f];
self.recordInfoTextView.text=@"Record 1 of 1";
[self.recordInfoTextView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
                                              UIViewAutoresizingFlexibleTopMargin)];

[self.view addSubview:recordInfoTextView];

UITextView将显示初始字符串值。但是,它不会在此处更新:

-(void)displayContentInTextView {
    self.recordInfoTextView.text=[NSString stringWithFormat:@"Record %d of %d", currentIndex+1, [idNumberArray count]];
    NSLog(@"displayContentInWebView: Record %d of %d", currentIndex+1, [idNumberArray count]);
}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
    if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
        if (currentIndex < ([idNumberArray count]-1)) {
            currentIndex++;
            recordID = [[idNumberArray objectAtIndex:currentIndex] intValue];
            [self displayContentInTextView];
        }
    } else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
        if (currentIndex > 0) {
            currentIndex--;
            recordID = [[idNumberArray objectAtIndex:currentIndex] intValue];
            [self displayContentInTextView];
        }
    }
}

日志显示正确调用displayContentInWebView并将预期信息发送到日志,但是,UITextView不会更新,而是继续显示初始文本。

提前致谢!蒂姆

1 个答案:

答案 0 :(得分:0)

似乎问题已经回答了但是:
你可以用self.recordInfoTextView替换所有recordInfoTextView它应该仍然可以工作,嘿,更少的代码:)