2013-02-11 48 views
0

我试图创建一个SplitViewController视图的方法,但我得到以下警告:物业需要定义

物业splitViewController需要将次使用@合成,@动态定义或提供一种方法一种方法setSplitViewController在这个类中实现实现。

下面是代码

///AppDelegate.h 

@class ViewController; 
@class DetailViewController; 

@interface AppDelegate : UIResponder <UIApplicationDelegate, UISplitViewControllerDelegate> 
{ 
UISplitViewController *splitViewController; 
ViewController *viewcontroller; 
DetailViewController *detailViewController; 
} 
@property (nonatomic,retain) UIWindow *window; 
@property (nonatomic,retain) DetailViewController *detailViewController; 
@property(nonatomic,retain) UISplitViewController *splitViewController; 
@property (nonatomic,retain) ViewController *viewController; 

@end 

///AppDelegate.m" 

#import "ViewController.h" 
#import "DetailViewController.h" 

@implementation AppDelegate 

@synthesize window = _window; 
@synthesize viewController = _viewController; 
@synthesize splitviewController; 
@synthesize detailViewController; 
- (void)dealloc 
{ 
    [_window release]; 
    [_viewController release]; 
    [super dealloc]; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    ViewController *rootViewController = [[ViewController alloc] initWithStyle:UITableViewStylePlain]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; 
    detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; 
    rootViewController.detailViewController = detailViewController;  

    splitViewController = [[UISplitViewController alloc] init]; 
    splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil]; 
    splitViewController.delegate = detailViewController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 




///ViewController.h 
#import <UIKit/UIKit.h> 
@class DetailViewController; 
@interface ViewController : UITableViewController{ 
DetailViewController *detailViewController; 
NSMutableArray *phone; 
} 
@property (nonatomic,retain)IBOutlet DetailViewController *detailViewController; 
@property (nonatomic,retain) NSMutableArray *phone; 
@end 



///ViewController.m 
#import "ViewController.h" 
#import "DetailViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize detailViewController,phone; 

    - (CGSize)contentSizeForViewInPopoverView { 
return CGSizeMake(320, 600); 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.phone = [[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"phone" ofType:@"plist"]] retain]; 

// Do any additional setup after loading the view, typically from a nib. 
    } 

    - (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return YES; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView { 
    // Return the number of sections. 
return 1; 
} 


- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { 
// Return the number of rows in the section. 
return [phone count]; 
} 


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"CellIdentifier"; 

// Dequeue or create a cell of the appropriate type. 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
} 

// Configure the cell. 
cell.textLabel.text = [self.phone objectAtIndex:indexPath.row]; 
return cell; 
} 
    - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    /* 
    When a row is selected, set the detail view controller's detail item to the item associated with the selected row. 
    */ 
detailViewController.detailItem = [self.phone objectAtIndex:indexPath.row]; 
} 
- (void)dealloc { 
[detailViewController release]; 
[super dealloc]; 
} 



    @end 

回答

0

在我们的代码,你有没有合成的splitViewController财产。既然你没有合成它的属性,编译器会发出一个警告,要求你合成该属性,以便它可以自动生成setter和getters(为了方便起见,你可以使用.所使用的.表示法生成setter和getters,所以如self.splitViewController那样合成它作为 @synthesize splitViewController = _splitViewController

实现自己定制的setter和getter作为

//setter 
- (void)setSplitViewController:(UISplitViewController*)splitViewController_ { 
    //assuming your property has retain identifier 
    if (splitViewController != splitViewController_) { 
     [splitViewController release]; 
     splitViewController = [splitViewController_ retain]; 
    } 
} 

//getter 
- (UISplitViewController*)splitViewController { 
    return splitViewController; 
} 

声明财产为动态使用@dynamic splitViewController。这意味着该属性的setter和getter将从其他地方提供。

编辑:

用以下替换appDelegate.m didFinishLaunchingWithOptions方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    _viewController = [[ViewController alloc] initWithNibName:@"ViewController's nib name" bundle:nil]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController]; 
    detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; 
    rootViewController.detailViewController = detailViewController;  

    splitViewController = [[UISplitViewController alloc] init]; 
    splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil]; 
    splitViewController.delegate = detailViewController; 

    self.window.rootViewController = splitViewController; 
    return YES; 
} 

还可以编辑的dealloc:

- (void)dealloc 
{ 
    [_window release]; 
    [_viewController release]; 
    [splitViewController release]; 
    [detailViewController release]; 
    [super dealloc]; 
} 

而在的viewController viewDidLoad更换self.phones与此一致

self.phone = [[NSArray的arrayWithObjects:@ “小区中的一个”,@ “细胞TWO”,@ “细胞THREE”,@ “细胞FOUR”,@ “细胞FIVE”,@ “细胞SIX”,零]。

这只是为了测试数组部分加载正确..所以你可以看到单元格,如果他们正在创建。在cellForRowAtIndexPath方法中设置一个断点并查看它是否被称为

然后最后在didSelect中查看detailItem iVar是否不为零。

是的,请在加载它们之前检查NIB名称,并确保NIB中的所有插座都已正确连接。

干杯和玩得开心。

+0

我已经尝试过@dynamic警告的清除,但得到空白screen.See代码。 – reddy 2013-02-11 07:39:49

+0

我正在编辑我的答案给你..检查这个并让我知道.. – croyneaus4u 2013-02-11 16:44:35

0

在你的情况增加@synthesize splitViewController = _splitViewController;detailViewController = _ detailViewController;

这里是有用的代码,我怎么能添加UISplitViewController

/// AppDelegate.h file 

#import <UIKit/UIKit.h> 
#import "MasterViewController.h" 
#import "DetailViewController.h" 


@interface AppDelegate : UIResponder <UIApplicationDelegate, UISplitViewControllerDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@property (nonatomic, strong) UISplitViewController *splitViewController; 
@property (nonatomic, strong) MasterViewController *masterVC; 
@property (nonatomic, strong) DetailViewController *detailVC; 

@property (nonatomic, strong) UINavigationController *mvcNavCon; 
@property (nonatomic, strong) UINavigationController *dvcNavCon; 

@end 


/// AppDelegate.m File 

#import "AppDelegate.h" 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    self.window.backgroundColor = [UIColor whiteColor]; 

    self.masterVC = [[MasterViewController alloc] init]; 
    self.mvcNavCon = [[UINavigationController alloc] initWithRootViewController:self.masterVC]; 

    self.detailVC = [[DetailViewController alloc] init]; 
    self.dvcNavCon = [[UINavigationController alloc] initWithRootViewController:self.detailVC]; 

    self.splitViewController = [[UISplitViewController alloc] init]; 
    self.splitViewController.delegate = self; 
    self.splitViewController.viewControllers = [NSArray arrayWithObjects:self.mvcNavCon, self.dvcNavCon,nil]; 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window.rootViewController = self.splitViewController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 
+0

我编辑了我的代码,请参阅。仍然显示空白屏幕。我的代码中出现了什么问题。 – reddy 2013-02-11 07:38:19

+0

检查我的代码与你的代码?你唔想?并且还给出了Ur viewController – iPatel 2013-02-11 07:40:41

+0

的特定的BackGroundColor视图。这个问题的概率是多少。我们不再接受来自这个帐户的问题。请参阅http://goo.gl/C1Kwu了解更多信息。 – reddy 2013-02-13 06:08:33

1

的问题是你在@synthesize声明拼错splitViewController - 你没有把握在V

,如果你做了最简单的方式你不会遇到这个问题。不再需要实例变量或@synthesize语句 - 您在创建属性时会同时自动获取。

+0

对不起,我们不再接受这个帐户的问题。请参阅http://goo.gl/C1Kwu了解更多信息。问题是什么 – reddy 2013-02-13 06:07:56