2010-12-13 11 views
0

HTMLParserを使用してHTMLコンテンツを解析しようとしています。その助けを借りて、UIAlertViewを開始しようとしていますが、アプリケーションは正常に動作しますが、UIAlertViewは起動しません。UIAlertViewが開始されていません

ここでは、コードです:

- (IBAction) loginButton: (id) sender 
{ 

// Create the username and password string. 
// username and password are the username and password to login with 
NSString *postString = [[NSString alloc] initWithFormat:@"username=%@&password=%@",userName, password]; 
// Package the string in an NSData object 
NSData *requestData = [postString dataUsingEncoding:NSASCIIStringEncoding]; 

// Create the URL request 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://localhost/dologin.php"]]; // create the URL request 
[request setHTTPMethod: @"POST"]; // you're sending POST data 
[request setHTTPBody: requestData]; // apply the post data to be sent 

// Call the URL 
NSURLResponse *response; // holds the response from the server 
NSError *error; // holds any errors 
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&error]; // call the URL 

/* If the response from the server is a web page, dataReturned will hold the string of the HTML returned. */ 

HTMLParser * parser = [[HTMLParser alloc] initWithData:returnData error:&error]; 

HTMLNode * bodyNode = [parser body]; 

NSArray * errorNodes = [bodyNode findChildTags:@"errorbox"]; 

for (HTMLNode * errorNode in errorNodes) { 
    if ([[errorNode getAttributeNamed:@"div class"] isEqualToString:@"errorbox"]){ 
     alertWithOkButton = [[UIAlertView alloc] initWithTitle:@"Status..." message:[NSString stringWithFormat:@"Invalid Access Info, try again"] delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil]; 
     [alertWithOkButton show]; 
     [alertWithOkButton release]; 
     //Login Failed 
    } 
} 

NSArray * spanNodes = [bodyNode findChildTags:@"clientarea.php?action=masspay"]; 

for (HTMLNode * spanNode in spanNodes) { 
    if ([[spanNode getAttributeNamed:@"action"] isEqualToString:@"clientarea.php?action=masspay"]){ 
     alertWithOkButton = [[UIAlertView alloc] initWithTitle:@"Status..." message:[NSString stringWithFormat:@"Login Accepted, redirecting to the main app screen. :)"] delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"Go",nil]; 
     [alertWithOkButton show]; 
     [alertWithOkButton release]; //Login Success 
    } 
} 

[parser release]; 

} 

答えて

0

メッセージあちこちあなたは[NSStringのstringWithFormat:]は必要ありませんがあなたのAlertViewsは、(適切に形成されているように見えますが、実際には何をフォーマットしていないので、ものを - だけであなたのメッセージは大丈夫です)。

これらは問題ないため、実際には表示されないような条件が発生することはありません。どちらのisEqualToString比較もtrueでないか、またはerrorNodesとspanNodesの両方が空であるか、それらの組み合わせがありません。

の最初のの横にあるをクリックし、ブレークポイントを設定します。ビルドとデバッグを行い、ブレークポイントに達するまでプログラムを実行させます。これで、errorNodesとspanNodesに実際に含まれているものを確認できます。

+0

問題はerrorNodeにありました。間違ったタグを使用したため、返されたデータは一致しませんでした。 :P –

関連する問題