0
我試圖在我的IOS應用程序中下載HTML,一旦我將html導入到我的應用程序中,我想搜索下載的數據並在兩個值之間打印文本。 例子:如果我從我的HTML數據得到這樣的數據: 內容-START狗想要做的事情,做的東西STOP將HTML下載到JSON
我想打印開始之間的文本,並在一個UITextView停止,以便人們可以查看文本乾淨。有沒有辦法做到這一點? 代碼我迄今:
@implementation FirstViewController
//http://www.streakadvice.com/path-to-the-stash-luke.html
- (void)viewDidLoad{
[super viewDidLoad];
if (myConnection == nil) {
myData = [NSMutableData new];
NSString *urlString = [NSString stringWithFormat:@"http://www.streakadvice.com/path-to-the-stash-luke.html"];
myConnection = [NSURLConnection connectionWithRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:urlString]]
delegate:self];
}
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"SFTCBR3.png"]]];
NSString *fullURL = @"http://www.streakadvice.com/path-to-the-stash-luke.html";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[myData appendData:data];
}
-(void)initializeVariablesAgain {
myData = nil;
myConnection = nil;
myTextView = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *stringToLookup = [[NSString alloc]initWithData:myData encoding:NSASCIIStringEncoding];
if ([stringToLookup rangeOfString:@"Start"].location != NSNotFound) {
myLabel.text = @" ";
} else {
myLabel.text = @" ";
}
myTextView.text = [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
[self initializeVariablesAgain];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end