我对Objective-C非常陌生。我刚刚搜索并试图了解UITableView
。UITableView for iOS
我已经创建了这个UITableView
。而不是所有行中的"a"
,我希望它的顺序如"a b c d..."
,如果我增加no行数,它应该滚动。它不滚动,所以这里是我的代码。
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
CGRect frame = self.view.frame;
UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.backgroundColor = [UIColor cyanColor];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellIDent"];
cell.textLabel.text = @"a";
return cell;
}
@end
您需要浏览一些iOS教程。检查http://www.raywenderlich.com/tutorials。还有'[super viewDidLoad];'应该是方法中的第一个调用。 – iDev
查看苹果公司的参考@ http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html –
我感谢您的兴趣,学习单元格索引行将返回单元格一个为了所以这里甚至第二个单元格返回一个。尝试改变该逻辑和滚动看到下面的答案,他们是美丽的框架。 –