开发者

Unable to set property on DetailViewController in an iPad app

EDIT: Figured it out. I was able to access the property through the appDelegate instance with appDelegate.detailViewController.thisRequest = aRequest;

I'm porting a fairly simple iPhone Navigation based app to a Split View iPad app. I have two nested levels of navigation on the Master view. The user picks a value from the first table and it loads the 2nd table. Selecting a value on the second table loads the Detail item for the detail view. Or it's supposed to. It's letting me set the property on the DetailViewController without an error, but it doesn't appear to be actually setting it. It's just null.

I'm following the SplitView template fairly closely. I'm only really getting off the beaten track by adding that 2nd TableViewController. My RootViewController loads the 2nd TableViewController on didSelectRowAtIndexPath, and that part's working. In my 2nd TableViewController.m I'm trying to set the detail item for the DetailView. In didSelectRowAtIndexPath I am able to get the object for my detail, but when I set it it doesn't set.

Here's the code:

First, in my DetailViewController, I set up a property for the object that will populate my fields (*thisRequest):

DetailViewController.h:

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {

UIPopoverController *popoverController;
UIToolbar *toolbar;

Request *thisRequest;
}

DetailViewController.m:

@interface DetailViewController ()
@property (nonatomic, retain) UIPopoverController *popoverController;
- (void)configureView;
@end

@implementation DetailViewController

@synthesize toolbar, popoverController, detailItem, detailDescriptionLabel;
@synthesize thisRequest;

Then, in my 2nd TableViewController, I try to maintain a reference to the DetailViewController (I suspect this is where I'm messing up; I still don't fully understand how things persist and exactly how to reference them in this framework).

RequestsTableViewController.h:

@class TrackerSplitViewAppDelegate, RequestsTableViewController,  DetailViewController;

@interface RequestsTableViewController : UITableViewController {
    NSString* selectedDepartmentID;
    NSMutableArray *requests;
    DetailViewController *detailViewController;
}

@property (nonatomic, retain) NSString* selectedDepartmentID;
@property (retain, nonatomic) NSMutableArray *requests;
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;

RequestsTableViewController.m:

@implementation RequestsTableViewController

@synthesize selectedDepartmentID;
@synthesize requests;
@synthesize detailViewController;

<snip>
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    TrackerSplitViewAppDelegate *appDelegate = (TrackerSplitViewAppDelegate *)[[UIApplication sharedApplication] delegate];

    Request *aRequest = [appDelegate.requests objectAtIndex:indexPath.row];
    detailViewController.thisRequest = aRequest;    
    NSLog(@"Request Loaded: %@", aRequest.Title);
    NSLog(@"detailViewController.thisRequest: %@", detailViewController.thisRequest.Title);
    [appDelegate release];

}

The aRequest object loads just fine, and the detailViewController.thisRequest = aRequest; line runs with no errors, but my log output looks like this:

2011-03-01 10:07开发者_运维百科:22.584 TrackerSplitView[8162:40b] Request Loaded: MyTitleString 2011-03-01 10:07:22.585 TrackerSplitView[8162:40b] detailViewController.thisRequest: (null)

Like I said, I still don't fully understand how everything gets passed around in the iOS framework, but the SplitNavigation template does something nearly identical to this with an id value and it works fine. The only differences I can see is the navigation layer isn't nested, as mine is, and also they don't use a pointer for the id since it's an integer instead of a custom object.

I'm guessing I'm not passing in the detailViewController to my RequestTableViewController properly, but I don't see how to do it.


EDIT: Figured it out. I was able to access the property through the appDelegate instance with appDelegate.detailViewController.thisRequest = aRequest;

On to the next bug.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜