Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-16-2011, 05:49 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default Selection in Master Controller doesn't Push to Detail Control

I have a master-detail application built that parses an RSS Feed. After compiling everything, it appears at first to work great. The feed items show in either the popover or master controller depending on portrait or landscape. When I select an article, it shows the article in the master controller and leaves the detail controller blank. Any ideas? Here are screenshots and code used. I removed some of the code from .m for parsing to get to the limit of characters.
Here is Master.h
Code:
#import <UIKit/UIKit.h>
@protocol MasterViewController <NSObject>

-(void)didTap:(NSString *)string;

@end
id delegate;
@class DetailViewController;

@interface MasterViewController : UITableViewController {
    NSOperationQueue *_queue;
    NSArray *_feeds;
    NSMutableArray *_allEntries;
}

@property (strong, nonatomic) DetailViewController *detailViewController;
@property (nonatomic, assign) id<MasterViewController> delegate;
@property (retain) NSOperationQueue *queue;
@property (retain) NSArray *feeds;
@property (retain) NSMutableArray *allEntries;

@end
Master.m
Code:
#import "MasterViewController.h"

#import "DetailViewController.h"
#import "RSSEntry.h"
#import "ASIHTTPRequest.h"
#import "GDataXMLNode.h"
#import "GDataXMLElement-Extras.h"
#import "NSDate+InternetDateTime.h"
#import "NSArray+Extras.h"
@implementation MasterViewController

@synthesize detailViewController = _detailViewController;
@synthesize allEntries = _allEntries;
@synthesize feeds = _feeds;
@synthesize queue = _queue;
@synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Master", @"Master");
        self.clearsSelectionOnViewWillAppear = NO;
        self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
    }
    return self;
}
- (void)refresh {
    
    for (NSString *feed in _feeds) {
        NSURL *url = [NSURL URLWithString:feed];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request setDelegate:self];
        [_queue addOperation:request];
    }
    
}							
- (void)dealloc
{	[delegate release];

    [_allEntries release];
    _allEntries = nil;
    [_queue release];
    _queue = nil;
    [_feeds release];
    _feeds = nil;

    [_detailViewController release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];    
	
    self.title = @"iPreacher";
	
    self.allEntries = [NSMutableArray array];
    self.queue = [[[NSOperationQueue alloc] init] autorelease];
    self.feeds = [NSArray arrayWithObjects:@"http://316apps.com/ipreachersblog/feed/",
                  nil];    
	
	
    [self refresh];
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_allEntries count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    
    RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
    
    NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
    
    cell.textLabel.text = entry.articleTitle;        
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", articleDateString, entry.blogTitle];
	
    return cell;
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.detailViewController) {
        self.detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] autorelease];
    }
    RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
    _detailViewController.entry = entry;
    [self.delegate didTap:[_allEntries objectAtIndex:indexPath.row]];
    [self.navigationController pushViewController:self.detailViewController animated:YES];
}

@end
Detail.h
Code:
#import <UIKit/UIKit.h>
@class RSSEntry;

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate> {
    UIWebView *_webView;
    RSSEntry *_entry;
	IBOutlet UIActivityIndicatorView *activity;
	NSTimer *timer;
	NSString *currentURL;
	
}
-(IBAction)action:(id)sender;
-(IBAction)save;
@property (retain) IBOutlet UIWebView *webView;
@property (retain) RSSEntry *entry;
@property (nonatomic, retain) UIActivityIndicatorView *activity;
@property (nonatomic, retain) NSString *currentURL;


@end
detail.m
Code:
#import "DetailViewController.h"
#import "RSSEntry.h"

@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end

@implementation DetailViewController


@synthesize masterPopoverController = _masterPopoverController;
@synthesize webView = _webView;
@synthesize entry = _entry;
@synthesize activity;
@synthesize currentURL;
- (void)dealloc
{[currentURL release];
    [_entry release];
    _entry = nil;
    [_webView release];
    _webView = nil;
        [_masterPopoverController release];
    [super dealloc];
}

#pragma mark - Managing the detail item

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle
/*
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    [self configureView];
}
*/
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated {
    
    NSURL *url = [NSURL URLWithString:_entry.articleUrl];    
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];
    self.title = @"iPreacher";
    
	timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
    
}
-(void)tick {
	if(!_webView.loading)
		[activity stopAnimating];
	else 
		[activity startAnimating];
	
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Detail", @"Detail");
    }
    return self;
}
							
#pragma mark - Split view

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
    barButtonItem.title = NSLocalizedString(@"Master", @"Master");
    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
    self.masterPopoverController = popoverController;
}

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    // Called when the view is shown again in the split view, invalidating the button and popover controller.
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    self.masterPopoverController = nil;
}

@end

__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 11-16-2011, 07:27 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Because you are pushing it with the master controller's navigation controller. I'm not too familiar with UIPopover's so I can give you any advice on how to make it work.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-17-2011, 04:32 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

Here is what I have changed so far. In .m
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (_webViewController2 == nil) {
			self.webViewController2 = [[[WebViewController2 alloc] initWithNibName:@"WebViewController2" bundle:nil] autorelease];
		}
		_webViewController2.detailItem = [_allEntries objectAtIndex:indexPath.row];
        
			}
}
WebViewController2 .h
Code:
#import <UIKit/UIKit.h>

@class RSSEntry;

@interface WebViewController2 : UIViewController <UISplitViewControllerDelegate, UIPopoverControllerDelegate> {
    UIWebView *_webView;
    RSSEntry *_entry;
	IBOutlet UIActivityIndicatorView *activity;
	NSTimer *timer;
	NSString *currentURL;
	id detailItem;
        UIPopoverController *masterPopoverController;
}
-(IBAction)action:(id)sender;
-(IBAction)save;
@property (retain) IBOutlet UIWebView *webView;
@property (retain) RSSEntry *entry;
@property (nonatomic, retain) UIActivityIndicatorView *activity;
@property (nonatomic, retain) NSString *currentURL;
@property (nonatomic, retain) id detailItem;

@end
.m
Code:
#import "WebViewController2.h"
#import "RSSEntry.h"
#import "SHK.h"
@interface WebViewController2 ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end

@implementation WebViewController2
@synthesize webView = _webView;
@synthesize entry = _entry;
@synthesize activity;
@synthesize currentURL;
@synthesize detailItem=_detailItem;
@synthesize masterPopoverController;

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        [_detailItem release]; 
        _detailItem = [newDetailItem retain]; 
        
        // Update the view.
        [self configureView];
    }
    
    if (self.masterPopoverController != nil) {
        [self.masterPopoverController dismissPopoverAnimated:YES];
    }        
}
- (void)configureView
{
    // Update the user interface for the detail item.
    
    
        NSURL *url = [NSURL URLWithString:_entry.articleUrl];    
        [_webView loadRequest:[NSURLRequest requestWithURL:url]];
        self.title = @"iPreacher";
        
        timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];    
}
It no longer shows the story in the master view, but nothing shows in the Detail View side. The xib is set to the class of WebViewController2, but nothing will load in it. Any thoughts?
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 11-19-2011, 02:51 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

I have been working on this non-stop and have still been unable to find a way to have my view controller on the right side of the split view listen to the left side. I am using Ray Wenderlich's tutorial for making a RSS Feed Reader. In MainWindow I add a Split View Controller and update the appdelegate file to properly show it on launch. Under the hierarchy in MainWindow.xib I change the navigation controller nib to Root View Controller, and under detail view controller I change class and nib to WebViewController2. I read and followed several tutorials online and edited my RootViewController.m TableView didSelectRowAtIndexPath to this:
Code:
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
        NSURL *url = [NSURL URLWithString:entry.articleUrl];    
        [webViewController2.webView loadRequest:[NSURLRequest requestWithURL:url]];
I then added a webview to the xib of WebViewController2 and connected it from the File's Owner properly. When I click the article from the left side of the split view controller, still nothing happens. I added a NSLog to get the URL of the webview in WebViewController2, and it shows null. So, for some reason, selecting the rowAtIndexPath is not properly passing on the site to the right side of the split view controller. I would greatly appreciate any advice.
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 398
17 members and 381 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0