我對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 –
我感謝您的興趣,學習單元格索引行將返回單元格一個爲了所以這裏甚至第二個單元格返回一個。嘗試改變該邏輯和滾動看到下面的答案,他們是美麗的框架。 –