thanks again for making me clearer. I have already gone through the book u referred Mr.RayNewbie.
Now i will make u more clearer where i have struck. The following code is the AppDelegate.h file,
#import <UIKit/UIKit.h>
#define kNameValueTag 1
#define kColorValueTag 2
@interface GVA_iPhoneAppDelegate : NSObject <UIApplicationDelegate,UITableViewDataSource,UITableViewDelegate> {
UIWindow *window;
IBOutlet UIViewController *vwController;
//NSArray *listData;
UITableView *myTable;
UIActivityIndicatorView *activityIndicator;
CGSize cellSize;
NSXMLParser *rssParser;
NSMutableArray *stories;
NSMutableDictionary *item;
NSString *currentElement;
NSMutableString *currentTitle, *currentDate, *currentSummary, *currentLink, *currentImage;
}
//@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic,retain) UIViewController *vwController;
@end
and here goes the appdelegate.m file,
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "GVA_iPhoneAppDelegate.h"
#import "DisclosureDetailButton.h"
@implementation GVA_iPhoneAppDelegate
@synthesize slideMenu, screenLabel, vwController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
myTable = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 120.0, 320.0, 310.0)];
myTable.dataSource = self;
myTable.delegate = self;
myTable.rowHeight = 120;
[window addSubview:myTable];
[window addSubview:vwController.view];
[window makeKeyAndVisible];
if([stories count] == 0) {
//NSString *pah = @"http://rss.feedsportal.com/c/865/f/11107/index.rss ";
[self parseXMLFileAtURL:@"http://rss.feedsportal.com/c/865/f/11107/index.rss "];
}
cellSize = CGSizeMake([myTable bounds].size.width,60);
}
- (void)parseXMLFileAtURL:(NSString *)URL {
stories = [[NSMutableArray alloc] init];
//you must then convert the path to a proper NSURL or it won't work
NSURL *xmlURL = [NSURL URLWithString:URL];
// here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
// this may be necessary only for the toolchain
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
// Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[rssParser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i )", [parseError code]];
NSLog(@"error parsing XML: %@", errorString);
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
currentImage = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentImage forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[stories addObject:[item copy]];
NSLog(@"adding story: %@", currentTitle);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentImage appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
NSLog(@"all done!");
NSLog(@"stories array has %d items", [stories count]);
[myTable reloadData];
}
- (void)dealloc {
[window release];
[myTable release];
[vwController release];
[super dealloc];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [stories count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GVAiPhone"];
if (cell == nil) {
//CGRect cellFrame = CGRectMake(0, 0, 300, 65);
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"GVAiPhone"] autorelease];
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_icon.png"]];
CGRect nameValueRect = CGRectMake(5, 5, 275, 35);
UILabel *nameValue = [[UILabel alloc] initWithFrame:nameValueRect];
nameValue.tag = kNameValueTag;
nameValue.font = [UIFont fontWithName:@"Arial" size:15.0];
nameValue.lineBreakMode = UILineBreakModeWordWrap;
nameValue.numberOfLines = 2;
[cell.contentView addSubview:nameValue];
[nameValue release];
CGRect colorValueRect = CGRectMake(5, 38, 275, 65);
UILabel *colorValue = [[UILabel alloc] initWithFrame:colorValueRect];
colorValue.tag = kColorValueTag;
colorValue.font = [UIFont fontWithName:@"Arial" size:11.0];
colorValue.textColor = [UIColor colorWithRed:130.0/255.0 green:135.0/255.0 blue:139.0/255.0 alpha:1.0];
colorValue.lineBreakMode = UILineBreakModeWordWrap;
colorValue.textAlignment = UITextAlignmentLeft;
colorValue.numberOfLines = 6;
[cell.contentView addSubview:colorValue];
[colorValue release];
}
// Set up the cell
//cell.text = [theSimpsons objectAtIndex:indexPath.row];
cell.hidesAccessoryWhenEditing = YES;
NSUInteger storyIndex = [indexPath row];
NSDictionary *rowData = [stories objectAtIndex:storyIndex];
UILabel *name = (UILabel *)[cell.contentView viewWithTag:kNameValueTag];
name.text = [rowData objectForKey:@"title"];
//name.lineBreakMode;
//UIImage *image =[UIImage imageNamed: currentImage];imageWithContentsOfFile
//image.size.width = 50;
//iimage.size.height = 50;
//cell.image = [UIImage imageNamed:currentImage];
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_icon.png"]];
UILabel *color = (UILabel *)[cell.contentView viewWithTag:kColorValueTag];
color.text = [rowData objectForKey:@"summary"];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DisclosureDetailButton *detButton = [[DisclosureDetailButton alloc]init];
//[self.vwController pushViewController:detButton animated:YES];
[self.vwController show];
[detButton release];
}
@end
with this code in Windows-based application, i parse the xml feeds from the link and display the data in a UITableView. For the detailed description of the particular data, i click on the cells of the table that should lead to an another view through the "didSelectRowAtIndexPath" method.
moreover you can find from the code that i don't use any Nib file. So can u please help me in sorting out that what subclass files (eg:UIViewController subclass) can i add to these base class file i.e. appDelegate.h file ?
so please provide a more clearer idea.
Thanks for your reply
-Sathiya