Ok I don't know why this isn't working, but I have hooked up a tableView, with 19 items of text I'd like to set to each cell.
The cells populate just fine, but when I try and scroll, it goes down there and I can see the cells that aren't visible on the initial view, it hangs, and won't scroll down. It just snaps back. REALLY WEIRD!
What am I doing wrong?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 19;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
if(indexPath.row == 0){
cell.textLabel.text = @"";
}else if(indexPath.row == 1){
cell.textLabel.text = @"";
}else if(indexPath.row == 2){
cell.textLabel.text = @"";
}else if(indexPath.row == 3){
cell.textLabel.text = @"";
}else if(indexPath.row == 4){
cell.indentationLevel = 2;
cell.textLabel.text = @"";
}else if(indexPath.row == 5){
cell.indentationLevel = 2;
cell.textLabel.text = @"";
}else if(indexPath.row == 6){
cell.indentationLevel = 2;
cell.textLabel.text = @"";
}else if(indexPath.row == 7){
cell.indentationLevel = 2;
cell.textLabel.text = @"";
}else if(indexPath.row == 8){
cell.indentationLevel = 2;
cell.textLabel.text = @"";
}else if(indexPath.row == 9){
cell.textLabel.text = @"";
}else if(indexPath.row == 10){
cell.textLabel.text = @"";
}else if(indexPath.row == 11){
cell.textLabel.text = @"";
}else if(indexPath.row == 12){
cell.textLabel.text = @"";
}else if(indexPath.row == 13){
cell.textLabel.text = @"";
}else if(indexPath.row == 14){
cell.textLabel.text = @"";
}else if(indexPath.row == 15){
cell.textLabel.text = @"";
}else if(indexPath.row == 16){
cell.textLabel.text = @"";
}else if(indexPath.row == 17){
cell.textLabel.text = @"";
}else if(indexPath.row == 18){
cell.textLabel.text = @"";
}
return cell;
}
I had the same problem.
Check the number of the row that you can't see.
After in your viewDidLoad, add this method:
I hope I have been helpful
I know it's an old question and this is not an answer to your question, but a suggestion to improve your code so others can benefit.
You could write this:
Instead of this:
And if you happen to have different text for each case you could either use:
Or even better to put everything inside an
NSArray
(database...) and just loop through them by the index.