Iphone 在执行代码之前未加载ipad子视图
我有一个命令,它应该在执行特定的时间密集型代码之前加载子视图。无论命令如何运行,都会及时执行代码,然后子视图显示出来。我能做些什么来解决这个问题吗Iphone 在执行代码之前未加载ipad子视图,iphone,ipad,Iphone,Ipad,我有一个命令,它应该在执行特定的时间密集型代码之前加载子视图。无论命令如何运行,都会及时执行代码,然后子视图显示出来。我能做些什么来解决这个问题吗 progressViewController = [[ProgressView alloc] initWithNibName:@"ProgressView" bundle:[NSBundle mainBundle]]; [self.view addSubview:[progressViewController view]]; NSString
progressViewController = [[ProgressView alloc] initWithNibName:@"ProgressView" bundle:[NSBundle mainBundle]];
[self.view addSubview:[progressViewController view]];
NSString *name=@"guy";
NSString *encodedName =[[NSString alloc] init];
int asci;
for(int i=0; i < [name length]; i++)
{
//NSLog(@"1");
asci = [name characterAtIndex:i];
NSString *str = [NSString stringWithFormat:@"%d,", asci];
encodedName =[encodedName stringByAppendingFormat: str];
}
NSString *urlString = [NSString stringWithFormat:@"someurl.com"];
NSURL *theUrl = [[NSURL alloc] initWithString:urlString];
NSString *result=[NSString stringWithContentsOfURL:theUrl];
result = [result substringFromIndex:61];
result = [result substringToIndex:[result length] - 20];
NSLog(result);
outLab.text=result;
[[progressViewController view] removeFromSuperview];
progressViewController=[[ProgressView alloc]initWithNibName:@“ProgressView”包:[NSBundle mainBundle]];
[self.view addSubview:[progressViewController视图]];
NSString*name=@“guy”;
NSString*encodedName=[[NSString alloc]init];
int asci;
对于(int i=0;i<[名称长度];i++)
{
//NSLog(@“1”);
asci=[name characterAtIndex:i];
NSString*str=[NSString stringWithFormat:@“%d”,asci];
encodedName=[encodedName stringByAppendingFormat:str];
}
NSString*urlString=[NSString stringWithFormat:@“someurl.com”];
NSURL*theUrl=[[NSURL alloc]initWithString:urlString];
NSString*result=[NSString stringWithContentsOfURL:theUrl];
结果=[result substringFromIndex:61];
结果=[结果子字符串到索引:[结果长度]-20];
NSLog(结果);
文本=结果;
[[progressViewController视图]从SuperView移除];
1)试试看
[self.view setNeedsUpdating]
添加子视图后
(二)
尝试将时间密集型线程拆分为另一个线程
- (void) f
{
// executed in main UI thread
progressViewController = [[ProgressView alloc] initWithNibName:@"ProgressView" bundle:[NSBundle mainBundle]];
[self.view addSubview:[progressViewController view]];
[NSThread detachNewThreadSelector:@selector(doCompute) toTarget:self
withObject:nil];
}
- (void) doCompute
{
// in a different thread....so we need a autoreleasepool
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
// do your computation here...
[self performSelectorOnMainThread:@selector(taskComplete:)
withObject:result waitUntilDone:NO];
[autoreleasepool release];
}
- (void) taskComplete
{
// executed in UI thread
[self.progressView removeFromSuperView];
}
您可以对视图进行子类化,然后使用viewDidLoad函数来执行长时间运行的代码