xml解析器的问题

时间:2013-02-26 01:39:14

标签: objective-c xml-parsing

我创建并运行了一个xml解析器,它运行得很漂亮。当我尝试建立新的请求和连接时出现问题......

新连接和请求有效,但解析器从不再次解析。我已将其设置为在按下按钮时再次运行代码。我已经调试了几个小时,我发现解析器再也没有运行过。

是否有解析器的方法调用可能会刷新它?我一直在寻找,但我找不到一个。

我一直在浏览文档,adn找不到任何关于让解析器重新解析的内容。

以下是代码示例:我正在使用nsxmlparser

//This function waits to fire until all loading is finished
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//Creates an instance of the singleton
DataArraySingleton *singleton = [DataArraySingleton sharedArray];
//Creates an array of the singleton's array
NSMutableData *theData = singleton.storedDataFromRequest;


parser = [[NSXMLParser alloc] initWithData:theData];

if (parser != nil)
{
    [parser setDelegate:self];
    [parser parse];
}





}

我确定第二次触发,因为我将断点设置为实际的解析方法,直到那时它才会运行。但是解析器再也不会发射了。

由于

这是我的按钮点击:

-(IBAction)onButtonClick:(id)sender
{
[theConnection cancel];

theConnection = nil;

userNameField = theTextField.text;

NSString *formattedUserNameString = [userNameField stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSString *twitterAPIString = @"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=";

NSString *formattedSearchString = [NSString stringWithFormat:@"%@%@", twitterAPIString, formattedUserNameString];

NSLog(@"%@", formattedSearchString);

//Creates a url from a string
theURL = [[NSURL alloc] initWithString:formattedSearchString];


if (theURL != nil)
{
    //Creates an NSURLRequest using hte url from above
    theRequest = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
    if (theRequest != nil)
    {
        //Establishes a connection using NSURLCOnnection with the request above
        theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
        [theConnection start];
    }
}
[theTextField resignFirstResponder];

}

0 个答案:

没有答案