iphone将值传递给其他类 [英] iphone passing value to other class

查看:97
本文介绍了iphone将值传递给其他类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RootViewController.m中有一点代码:

I have one bit of code inside RootViewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

 NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
 BlogRssParser *blogRss = [[BlogRssParser alloc] init];
 blogRss.terms = [[selectedObject valueForKey:@"data"] description];
 //[blogRss setSelectedObject:selectedObject];
 NSLog(@"%@", blogRss.terms);

 RssFunViewController *rssFun = [[RssFunViewController alloc] initWithNibName:@"RssFunViewController" bundle:nil];
 [self.navigationController pushViewController:rssFun animated:YES];
 [rssFun release];

}

该行,它转到RssFunViewController。但它使用BlogRssParser来填充RssFun的tableview。所以我想尝试之间,并从RootView发送一个值到BlogRss,所以它填充RssFun正确的数据。

So when the user clicks the row, it goes to RssFunViewController. But it uses BlogRssParser to fill RssFun's tableview. So i'm trying to get between that and send a value from RootView to BlogRss so it fills RssFun with the right data.

我有这个在BlogRssParser.m: / p>

i have this in BlogRssParser.m:

-(BOOL)fetchAndParseRss{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    //To suppress the leak in NSXMLParser
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];

    NSLog(@"%@", self.terms);

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://news.search.yahoo.com/rss?ei=UTF-8&p=%@&fr=news-us-ss", self.terms]];
    NSLog(@"%@", url);

    BOOL success = NO;
    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:YES];
    [parser setShouldReportNamespacePrefixes:YES];
    [parser setShouldResolveExternalEntities:NO];
    success = [parser parse];
    [parser release];
    [pool drain];
    return success;
}

在控制台中,RootView中的术语日志具有正确的值。但在BlogRssParser,它出现为(null)。我已经在BlogRssParser.m中声明了作为属性的条件。

In the console, the log of terms in RootView has the right value. But in BlogRssParser, it comes up as (null). I have declared terms as a property in BlogRssParser.m.

这是我如何声明的:

 @interface BlogRssParser : NSObject {
    BlogRss * _currentItem;
    NSMutableString * _currentItemValue;
    NSMutableArray * _rssItems;
    id<BlogRssParserDelegate> _delegate;
    NSOperationQueue *_retrieverQueue;
    //NSManagedObject *selectedObject;
    NSString *terms;
}


@property(nonatomic, retain) BlogRss * currentItem;
@property(nonatomic, retain) NSMutableString * currentItemValue;
@property(readonly) NSMutableArray * rssItems;
//@property(nonatomic,retain) NSManagedObject *selectedObject;
@property(nonatomic, retain) NSString *terms;

@property(nonatomic, assign) id<BlogRssParserDelegate> delegate;
@property(nonatomic, retain) NSOperationQueue *retrieverQueue;


推荐答案

使用 self.terms 。除了访问器方法之外,你不应该使用底层的ivar。

Use self.terms instead. You shouldn't use the underlying ivar apart from inside the accessor methods.

这篇关于iphone将值传递给其他类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆