我已經用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