I have a simply MainWindow file created by the Interface Builder in black background. Inside this plain view, I've added from top to bottom a small view (300x100), a textLabel and a couple of buttons.
In the MainApplication.h I've defined:
IBOutlet RoundRectView* smallView; IBOutlet UILabel* label;
In the MainApplication.h I开发者_开发百科've @synthesized these variables and with that:
[label setText:@"Test"];
I can see all in my screen and it works perfect.
Now my problem:
I want to add a table with two rows inside my small white view, and what I've done is:
- Create a tableController.h who's the delegate and the data source:
@interface IncomeExpenseController : UITableViewController { IBOutlet UITableView* smallTable; NSArray *content; }
@property (nonatomic, retain) UITableView *smallTable; @property (nonatomic, retain) NSArray *content;
@end
- Create the .m file with:
@synthesize smallTable; @synthesize content;
(void)viewDidLoad { [super viewDidLoad]; content = [[NSArray alloc] initWithObjects:@"Item1", @"Item2", 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. return 2; }
// 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSLog(@"inside cell");
// Configure the cell... cell.textLabel.text = [content
objectAtIndex:indexPath.row];
return cell; }
Now in the Interface Builder, I drag and drop a UITableView inside the white small view and drag and drop a Table View Controller along with the File Owner's window and I do these connections:
Class of the Table View Controller to tableController
Outlets: DataSource and Delegate to my Table Controller
Referencing Outlets: customTable and View to my Table Controllers
When I execute, I can see the lines of the table view but with no content, I cannot see the NSLog either but if I put a NSLog inside the viewDidLoad I can see it.
I'm really new (2 days) on that and any help would be really appreciated.
Thanks!
Solved.
First of all, the TableView is grouped so I must return almost one section. Second, from the Interface Builder, I had to link the "view" from the Table to my external controller.
Now it works perfectly.
精彩评论