loading data in uitable view
i am developing a simple view based application which contains two buttons and a table view which parses the rss feed.my view has got two buttons at the top and i am adding uitableview from interface builder...ive added delegate and data source of the table view as file s owner....the parsing process is done in a seperate file and i am using delgation to receive the parsed data....every thing works fine except for [self.tableView reloadData] which gives an error and if i am to comment this i m not getting the data to be loaded in the table view.......this loading of parsed data works fine if im to create a navigation based application.but if i am to create a view based application and add table view progrmatically from interface builder creates problem ,cud u guys help me out....below is the code..
@implementation FirstViewController
@synthesize items;
@synthesize items2;
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadData];
}
-(void)loadData
{
if (items==nil)
{
Parser1 *rssparser=[[Parser1 alloc]init];
rssparser.delegate=self;
[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
[activityIndicator startAnimating];
[rssparser startRssFeed:@"http://api.flickr.com/services/feeds/photos_public.gne"];
[rssparser release];
}else
{
//[self.tableView reloadData];
}
}
-(void)receiveFeeds:(NSArray *)theItems
{
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
[activityIndicator stopAnimating];
items=theItems;
NSLog(@"ha ha ha items:%@",items);
//[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [items count];
}
- (UITableVie开发者_Go百科wCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[[items objectAtIndex:indexPath.row]objectForKey:@"title"];
cell.textLabel.text=@"hello";
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Try running your app with NSZombieEnabled = YES in the environment settings. Maybe you have a memory allocation issue somewhere.
My educated guess is that: items=theItems;
you do not retain the items array and it gets autoreleased before you use it
精彩评论