2010-07-06 31 views
-1

我是新來的客觀c編程我想調用anothor方法內的函數請給我想法。如何調用目標中的類內函數c

-(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]; 

} 

,但它不工作,請幫我謝謝。

回答

2

你需要閱讀的初學者文檔,從這裏開始:專門Learning Obj-C

對於您的問題,試試這個:

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

請查看我的問題我編輯它 – 2010-07-06 09:57:57

+0

挑剔,你的第二行是一個錯字 - 應該是「aBlogAddress」,而不是「blogAddress」。否則,100%同意。 – Kalle 2010-07-06 11:31:20

+0

@Kalle thks,我編輯了它 – Greensource 2010-07-06 13:55:45

1

就像你已經在使用self一樣,但你必須正確地提供參數。

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

blogAddress是一個NSString,你必須以某種方式提供。例如,如果您的應用程序中有一個名爲textViewRSSFeed的文本視圖,則會爲該字段提供值。

[self grabRSSFeed:textViewRSSFeed.text]; 
+0

請查看我的問題,我有編輯它 – 2010-07-06 09:56:58

+0

Greensource現場 - 你需要去RTFM。你的問題是通過[self grabRSSFeed:feedurl]解決的;儘管如此,它是值得的。 – Kalle 2010-07-06 10:09:53

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



    } 


-(void)ViewDidLoad 
    { 
    NSString *[email protected]"www.anyUrl.com"; 

    [Self grabRssFeed:Str]; 

    }