未为 uiSplitView 的主视图调用 UITableView 委托方法

发布于 2024-11-25 20:23:10 字数 2746 浏览 1 评论 0原文

我有一个带有按钮的视图。当我按下按钮时,应该显示 uisplitview。问题在于表视图(分割视图的左=主视图)。详细视图(右)正确显示。左侧为空,因为未调用 cellForRowAtIndexPath。 我的 .h 文件扩展了 UISplitViewController,在 .m 文件的 viewDidLoad 中我这样做:

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];

My left.h:

@interface Left : UIViewController  <UITableViewDataSource, UITableViewDelegate> {

NSMutableArray *tableData;
UITableView *table;
}

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

My 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

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

I have a view with button. When i press a button, uisplitview should show. The problem is that with the tableview (splitview's left=master view). The detail view (right) is displayed correctly. Left one is empty because cellForRowAtIndexPath is not called.
My .h file extends UISplitViewController, and in the .m file's viewDidLoad i do this:

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];

My left.h:

@interface Left : UIViewController  <UITableViewDataSource, UITableViewDelegate> {

NSMutableArray *tableData;
UITableView *table;
}

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

My 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

How can i fill my master view's table with data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2024-12-02 20:23:10

你必须

替换它

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

,因为

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

我曾经用 self 来调用你已经合成了表格。

所以我们必须喜欢这个

u have to

replace this

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

to

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

becuase i have used to call with self is u have synthesized the table.

so we have to like this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文