2011-07-22 40 views
1

我有一个按钮的视图。当我按下按钮时,应显示uisplitview。问题在于tableview(splitview的left = master view)。详细视图(右)显示正确。因为cellForRowAtIndexPath没有被调用,所以左边的是空的。 我的h文件扩展UISplitViewController,并在.m文件的viewDidLoad我这样做:UITableView委托方法不调用uiSplitView的主视图

Left *l = [[Left alloc] initWithNibName:@"Left" bundle:nil]; 
Right *d = [[Right alloc] initWithNibName:@"Right" bundle:nil]; 
// Update the split view controller's view controllers array. 
NSArray *viewControllers = [[NSArray alloc] initWithObjects:l, d, nil]; 
self.viewControllers = viewControllers; 
[viewControllers release]; 

我left.h:

@interface Left : UIViewController <UITableViewDataSource, UITableViewDelegate> { 

NSMutableArray *tableData; 
UITableView *table; 
} 

@property (nonatomic, retain) NSMutableArray *tableData; 
@property (nonatomic, retain) IBOutlet UITableView *table; 

我left.m:

#import "Left.h" 


    @implementation Left 

    @synthesize tableData,table; 

    - (id)initWithStyle:(UITableViewStyle)style 
    { 
self = [super initWithStyle:style]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)dealloc 
{ 
[super dealloc]; 
} 

- (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. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 

[super viewDidLoad]; 
table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; 
table.delegate = self; 
table.dataSource = self; 

table.autoresizesSubviews = YES; 
tableData=[[NSMutableArray alloc] initWithObjects:@"bazinga",@"buzz", nil]; 

//NSLog(@"velikost : %d", [tableData count]); 
[self.view addSubview:table]; 
} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 

// Return the number of sections. 
return 0; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

// Return the number of rows in the section. 
NSLog(@"size: %d", [tableData count]); 
return [tableData count]; 
    } 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell... 
cell.textLabel.text=[tableData objectAtIndex:indexPath.row]; 

return cell; 
} 


    } 

    @end 

我如何使用数据填充主视图的表格?

回答

0

u必须

替换此

table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; 

self.table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; 

监守我已经使用自调用是u必须合成表。

所以我们必须这样