我已经用google搜索并在这里搜索了stackoverflow,但一直没有找到解决办法。为什么我的UITableView显示不能?
我期待发生的事情:的UITableView显示和显示单元包含 “喜”
会发生什么:的UITableView甚至不显示
viewViewController.h
#import <UIKit/UIKit.h>
@interface viewViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITableView *tableView;
//note: the above property is connected to my UITableViewController
@end
viewViewController.m
#import "viewViewController.h"
@interface viewViewController()
@end
@implementation viewViewController
@synthesize tableView = _tableView;
- (UITableView *)tableView
{
if (!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
}
return _tableView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//_tableView = [[UITableView alloc] init];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
//[self setTableView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//warning Potentially incomplete method implementation.
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"asking for rows");
//#warning Incomplete method implementation.
// Return the number of rows in the section.
switch (section)
{
case 0:
return 5;
case 1:
return 10;
break;
default:
return 0;
break;
}
}
- (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];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = @"hi";
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"testtext";
}
@end
请告诉我我做错了什么,并更正了我的代码。
FileOwner是什么意思?对不起,我有点新东西。 – blake305 2012-01-04 21:43:52
另外,我使用故事板,如果这有助于任何。 – blake305 2012-01-04 21:44:22
@ blake305他的意思是任何人要实现协议方法,即委托,在你的情况下,它是viewViewController。如果您无法使用Storyboard在代理中连线,请在viewViewController的viewDidLoad中执行'_tableView.delegate = self'和'_tableView.dataSource = self' - 假设您将协议包含在标题中:'@interface viewViewController:UIViewController' –
Jeremy
2012-01-04 22:03:38