如何在目标c中调用类中的函数

时间:2010-07-06 09:32:01

标签: iphone objective-c

我是客观c编程新手我想在anothor方法中调用一个函数请给我一个想法。

-(void) grabRSSFeed:(NSString *)blogAddress {

    // Initialize the blogEntries MutableArray that we declared in the header
    myBlogEntries = [[NSMutableArray alloc] init];  

    // Convert the supplied URL string into a usable URL object
    NSURL *url = [NSURL URLWithString: blogAddress];

    // Create a new rssParser object based on the TouchXML "CXMLDocument" class, this is the
    // object that actually grabs and processes the RSS data
    CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];

    // Create a new Array object to be used with the looping of the results from the rssParser
    NSArray *resultNodes = NULL;

    // Set the resultNodes Array to contain an object for every instance of an  node in our RSS feed
    resultNodes = [rssParser nodesForXPath:@"//item" error:nil];

    // Loop through the resultNodes to access each items actual data
    for (CXMLElement *resultElement in resultNodes) {

        // Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries
        NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init];

        // Create a counter variable as type "int"
        int counter;

        // Loop through the children of the current  node
        for(counter = 0; counter < [resultElement childCount]; counter++) {

            // Add each field to the blogItem Dictionary with the node name as key and node value as the value
            [blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];

        }       
        // Add the blogItem to the global blogEntries Array so that the view can access it.
        [myBlogEntries addObject:[blogItem copy]];

    }  
}

想要在宝贝方法中调用上述功能

    -(IBAction)babes
{   
    myview.hidden = FALSE;

    [myview startAnimating];



    feedurl = @"http://www.luxury.net/feed/rss/babes.xml";
    //want to call it here.....

    [self performSelector:@selector(moveAlert:) withObject:nil afterDelay: 0.7f];

}

但它不起作用请提前帮助我。

3 个答案:

答案 0 :(得分:2)

您需要阅读初学者文档,从这里开始:Learning Obj-C

具体来说,请尝试以下方法:

NSString* aBlogAdress = @"http://anAdress.com";
[self grabRSSFeed:aBlogAddress];

答案 1 :(得分:1)

您正如您所做的那样使用self,但您必须正确提供参数。

[self grabRSSFeed:@"http://someurl.com"];

blogAddress是一个NSString,你必须以某种方式提供。例如,如果您的应用中有一个名为textViewRSSFeed的文本视图,则会提供该字段的值。

[self grabRSSFeed:textViewRSSFeed.text];

答案 2 :(得分:1)

    -(void)grabRssFeed:(NSString *)str
    {



    }


-(void)ViewDidLoad
  {
  NSString *Str=@"www.anyUrl.com";

  [Self grabRssFeed:Str];

   }