Objective c 访问数组中要在UITableViewCell中显示的对象的属性

Objective c 访问数组中要在UITableViewCell中显示的对象的属性,objective-c,arrays,object,properties,uitableview,Objective C,Arrays,Object,Properties,Uitableview,我正在使用XML解析器从博客中获取信息,以创建提要阅读器应用程序。我创建了一个对象,其属性是每个博客条目(标题、发布、作者…)的数据。我将数据存储在对象中,然后使用指针将对象放入解析数据数组中。当我访问属性以在UITableView中显示它们时,每个单元格都是相同的,每个单元格都有最后一个博客条目的数据 parser.m文件 @interface Parser() //This property holds the blog objects that were parsed @property

我正在使用XML解析器从博客中获取信息,以创建提要阅读器应用程序。我创建了一个对象,其属性是每个博客条目(标题、发布、作者…)的数据。我将数据存储在对象中,然后使用指针将对象放入解析数据数组中。当我访问属性以在UITableView中显示它们时,每个单元格都是相同的,每个单元格都有最后一个博客条目的数据

parser.m文件

@interface Parser()

//This property holds the blog objects that were parsed
@property (nonatomic, strong) NSMutableArray *parsedResults;

//This property holds the current element content being parsed
@property (nonatomic, strong) NSString *currentElement;

@property (nonatomic, strong) FRFeedItem *blogEntry;

@end


@implementation SolsticeParser

@synthesize parsedResults = _parsedResults;
@synthesize currentElement = _currentElement;

// Will be used to truncate data parsed from publish tag so that it will only store the YYYY-MM-DD to self.blogEntry.datepublished
NSRange dateOnly = {0, 10};

//This method initializes the parser, sets the delegate, starts parsing, and returns the results.
- (NSMutableArray *)parseFeedWithResults:(NSURL *)URL
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
parser.delegate = self;
self.parsedResults = [[NSMutableArray alloc] init];
[parser parse];             // Everything parsed here
return self.parsedResults;
}
…此处解析的数据保存到BlogEntry对象的属性中

#pragma mark - Parser delegate

- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{

// Custom blog object initialized here
     if ([elementName isEqualToString:@"entry"]) {
        if (!self.blogEntry) {
            self.blogEntry = [[FRFeedItem alloc] init];

        }
    }

}
...

- (void)parser:(NSXMLParser *)parser
 didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName {

if([elementName isEqualToString:@"title"]) {
    self.blogEntry.title = self.currentElement;

} else if([elementName isEqualToString:@"published"]) {
    self.blogEntry.datePublished = [self.currentElement substringWithRange:dateOnly];

} else if([elementName isEqualToString:@"entry"]) {
    [self.parsedResults  addObject:self.blogEntry];
}
}
在MyTableViewController.m中:

@interface MyTableViewController ()

@property (nonatomic, strong) Parser* parser;
@property (nonatomic, strong) NSMutableArray* feedDataFromParser;

@end

@implementation MyTableViewController

 // synthesize automatically done by Xcode v4.6

- (void)viewDidLoad
{
[super viewDidLoad];
self.parser = [[Parser alloc] init]; // initialize parser by allocating memory on the heap
[self loadItems]; // automatically loads data to be displayed upon opening the app

}

- (void)loadItems
{
// information parsed from blog stored to a mutable array
self.feedDataFromParser = [self.parser parseFeedWithResults:[NSURL URLWithString:kFeedURL]];
}

...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//code not included for this question for brevity

// Configure the cell from data stored in mutable array of FRFeedItem objects
// PROBLEM:
cell.textLabel.text = [[self.feedDataFromParser objectAtIndex:indexPath.row] title];
cell.detailTextLabel.text = [[self.feedDataFromParser objectAtIndex:indexPath.row] datePublished];

return cell;
}
@end
就我所知,在语法上没有什么错误。我已经尝试打印出解析并保存到解析器文件中的对象的数据以及indexPath.row的值,这两个都是正确的。
我遗漏了什么???

我认为问题在于这一行:

if (!self.blogEntry)

创建第一个后,将不再创建。尝试删除if子句,看看是否可以修复它。

出现了什么错误?在哪里以及如何创建feedDataFromParser?如果您记录它,它是否只显示一个对象?@VishnuPrasath没有错误。问题是,当我运行模拟器时,表中有适当数量的单元格(等于解析的博客条目的数量),但它们都是相同的(即,最后解析的博客条目的数量)。@rdelmar在MyTableViewController.m中声明为
@property(nonatomic,strong)NSMutableArray*feedDataFromParser。其内容是解析返回的数组:
self.feedDataFromParser=[self.parser parseFeedWithResults:[NSURL URLWithString:kFeedURL]]如何创建它我问--显示代码。还有,日志呢?日志显示了什么?非常感谢你…我要花更多的时间才能弄清楚。工作100%