我的应用程序中有一堆文本视图。出于某种原因,无论我以编程方式(来自互联网)还是通过界面构建器(硬编码)设置 UITextView 文本,无论我做什么,当我在测试时转到该文本视图时它是空白的。但是当我滚动它的那一刻,所有的文字就突然出现了。澄清一下,我并不是说文本视图不会滚动,因为没有足够的文本。textview 已将文本编程到其中,但在应用程序运行时它不会显示任何文本,直到 textview 实际滚动,然后文本才出现。
有人知道怎么修这个东西吗?我已经尝试取消链接视图并重新链接以及所有内容。
代码:h文件
@interface AboutViewController : UIViewController
{
IBOutlet UITextView *textView;
NSMutableData *responseData;
NSString *res;
}
@property(nonatomic,retain)IBOutlet UITextView *textView;
@property (nonatomic,retain)NSMutableData *responseData;
@end
文件
#import "AboutViewController.h"
@interface AboutViewController ()
@end
@implementation AboutViewController
@synthesize responseData= _responseData;
@synthesize textView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.someurl.com"]];
[NSURLConnection connectionWithRequest:req delegate:self];
}
return self;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if (!_responseData) {
[self setResponseData:[NSMutableData data]];
}
[_responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)URLresponse {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)URLresponse;
if (![httpResponse isKindOfClass:[NSHTTPURLResponse class]]) {
NSLog(@"Unknown response type: %@", URLresponse);
return;
}
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
res=[[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];
textView.text = res;
NSLog(@"RES:%@",res);
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)dealloc{
[super dealloc];
[res release];
}
@end