【发布时间】:2015-01-11 02:14:45
【问题描述】:
我正在制作一个表格视图,当显示 1-10 行时,一切正常。但是,当添加超过 10 行时。它正在构建,但在模拟器中,它只显示 10 行。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.greekLetters=
@[@"CHEM 1100",@"CHEM 2100 ",@"CHEM 3415W",@"CHEM 3511",@"CHEM 3521",@"CHEM 4600",@"PHYS 1150",@"PHYS 2150",@"MATH 1201",@"MATH 1206",@"Adv courses",@"CHEM 2700"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.greekLetters count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *SimpleIdentifier=@"SimpleIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleIdentifier];
if (cell ==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:SimpleIdentifier];
}
cell.textLabel.text=self.greekLetters[indexPath.row];
if(indexPath.row==0) cell.detailTextLabel.text=@"General Chemistry I";
if(indexPath.row==1) cell.detailTextLabel.text=@"General Chemistry II";
if(indexPath.row==2) cell.detailTextLabel.text=@"Analytical Chemistry";
if(indexPath.row==3) cell.detailTextLabel.text=@"Organic Chemistry I";
if(indexPath.row==4) cell.detailTextLabel.text=@"Organic Chemistry II";
if(indexPath.row==5) cell.detailTextLabel.text=@"Physical Chemistry(HP)";
if(indexPath.row==6) cell.detailTextLabel.text=@"General Physics I";
if(indexPath.row==7) cell.detailTextLabel.text=@"General Physics II";
if(indexPath.row==8) cell.detailTextLabel.text=@"Calculus I";
if(indexPath.row==9) cell.detailTextLabel.text=@"Calculus II";
if(indexPath.row==10) cell.detailTextLabel.text=@"pick 5 creit";
if(indexPath.row==11) cell.detailTextLabel.text=@"Introduction to Inorganic Chemistry";
return cell;
}
-(NSIndexPath *) tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
return indexPath;
}
请问是我的代码问题还是模拟器的问题?是不是因为当我把 tableview 放在 stroyboard 上时,有什么不对劲的地方?
【问题讨论】:
-
您可能基于此的 YouTube 教程系列中有一些非常奇怪的东西:(
-
是的,我只是按照那个教程。但我看不出这么简单的代码有什么问题。请问你有什么想法吗?谢谢。
-
您确定您的表格视图完全在情节提要的范围内吗?您是否正确设置了约束?
-
感谢您的回复。请问怎么查边界?我没有任何限制。
-
您是在 StoryBoard 中创建这个吗?
标签: ios uitableview tableview