Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // NewsTitleViewController.m
- // Hamshahri
- //
- // Created by Neeku on 1/4/12.
- // Copyright 2012 __MyCompanyName__. All rights reserved.
- //
- #import "NewsTitleViewController.h"
- #import "RssParser.h"
- #import "RssData.h"
- #import "NewsDetailViewController.h"
- #import "CategoryData.h"
- #import "proAlertView.h"
- #define MAINLABEL_TAG 1
- #define SECONDLABEL_TAG 2
- #define PHOTO_TAG 3
- #pragma mark -
- @implementation NewsTitleViewController
- @synthesize rssParser;
- @synthesize tableView;
- @synthesize labelText;
- @synthesize myCategoryData;
- @synthesize activityIndicator;
- #pragma mark - View lifecycle
- - (void)viewDidLoad
- {
- [activityIndicator startAnimating];
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- self.title = myCategoryData.categoryName;
- rssParser = [[RssParser alloc] init];
- [[self rssParser] setMyCategoryData:[self myCategoryData]];
- [[self rssParser] setDelegate:self];
- [[self rssParser] startProcess];
- self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"Background"]];
- self.tableView.separatorColor = [UIColor darkGrayColor];
- self.tableView.backgroundColor = [UIColor clearColor];
- }
- - (void)viewDidUnload
- {
- [self setLabelText:nil];
- [self setActivityIndicator:nil];
- [super viewDidUnload];
- }
- - (void) processCompleted
- {
- [[self tableView] reloadData];
- [activityIndicator stopAnimating];
- }
- - (void) processHasErrors
- {
- //Due to internet connection or server error.
- proAlertView *alert = [[proAlertView alloc] initWithTitle:@"همشهری" message:@"دسترسی به مطالب سایت مقدور نشد. لطفاً ارتباط اینترنت خود را بررسی نمایید." delegate:self cancelButtonTitle:@"تایید" otherButtonTitles:nil];
- [alert setBackgroundColor:[UIColor colorWithRed:0.1804 green: 0.3020 blue:0.1647 alpha:0.4] withStrokeColor: [UIColor colorWithHue:0.625 saturation:0.0 brightness: 0.8 alpha:0.5]];
- [alert show];
- [alert release];
- [activityIndicator stopAnimating];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [[[self rssParser] rssItems] count];
- }
- - (UITableViewCell *)tableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UILabel *mainLabel, *secondLabel;
- UIImageView *photo;
- UITableViewCell * cell = [myTableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
- if(nil == cell)
- {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"rssItemCell"] autorelease];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 15.0)] autorelease];
- mainLabel.tag = MAINLABEL_TAG;
- mainLabel.font = [UIFont systemFontOfSize:14.0];
- mainLabel.textAlignment = UITextAlignmentRight;
- mainLabel.textColor = [UIColor whiteColor];
- mainLabel.backgroundColor = [UIColor clearColor];
- mainLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [cell.contentView addSubview:mainLabel];
- secondLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 20.0, 300.0, 25.0)] autorelease];
- secondLabel.tag = MAINLABEL_TAG;
- secondLabel.font = [UIFont systemFontOfSize:10.0];
- secondLabel.textAlignment = UITextAlignmentRight;
- secondLabel.textColor = [UIColor lightGrayColor];
- secondLabel.backgroundColor = [UIColor clearColor];
- secondLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [cell.contentView addSubview:secondLabel];
- photo = [[[UIImageView alloc] initWithFrame:CGRectMake(225.0, 0.0, 80.0, 45.0)] autorelease];
- photo.tag = PHOTO_TAG;
- photo.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [cell.contentView addSubview:photo];
- UITableViewCell * cell = [myTableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
- if (nil == cell)
- {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"]autorelease];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- }
- else
- {
- mainLabel = (UILabel *) [cell.contentView viewWithTag:MAINLABEL_TAG];
- secondLabel = (UILabel *) [cell.contentView viewWithTag:SECONDLABEL_TAG];
- photo = (UIImageView *) [cell.contentView viewWithTag:PHOTO_TAG];
- }
- RssData *data = [[[self rssParser] rssItems] objectAtIndex:indexPath.row];
- mainLabel.text = [data title];
- secondLabel.text = [data description];
- }
- //To customize the selected tableview cell
- //cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"effect"]]autorelease];
- [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NewsDetailViewController *dvcontroller = [[NewsDetailViewController alloc] initWithNibName:@"NewsDetailViewController" bundle:nil];
- RssData *rssData = [[[self rssParser] rssItems] objectAtIndex:indexPath.row];
- //New Allowance
- [dvcontroller setRssData:rssData];
- [[self navigationController] pushViewController:dvcontroller animated:YES];
- [dvcontroller release];
- }
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- // Return YES for supported orientations.
- return YES;
- }
- - (void)didReceiveMemoryWarning
- {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- //This UIViewController is about to re-appear, make sure we remove the current selection in our table view.
- NSIndexPath *tableSelection = [self.tableView indexPathForSelectedRow];
- [self.tableView deselectRowAtIndexPath:tableSelection animated:NO];
- }
- - (void)setTitle:(NSString *)title
- {
- [super setTitle:title];
- UILabel *titleView = (UILabel *)self.navigationItem.titleView;
- if (!titleView)
- {
- titleView = [[UILabel alloc] initWithFrame:CGRectZero];
- titleView.backgroundColor=[UIColor clearColor];
- titleView.font = [UIFont boldSystemFontOfSize:20.0];
- titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
- titleView.textColor = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.0];
- self.navigationItem.titleView = titleView;
- [titleView release];
- }
- titleView.text = title;
- [titleView sizeToFit];
- }
- - (void) dealloc
- {
- [tableView release];
- [rssParser release];
- [myCategoryData release];
- [labelText release];
- [activityIndicator release];
- [super dealloc];
- }
- @end
Add Comment
Please, Sign In to add comment