How to fix Row in table in Uitableview in iphone
I am small basic module. I have 3 screen in this module. First screen is welcome message showing. Second screen is Table view which is contacting 3 Row with the title. Whenever user will select any row Full Text will be open for selected row. Last screen is containing one BACK button which will back to second screen (on tableview screen).
I have done this all till last screen. But when I am clicking on back button I am going on table view screen but 开发者_如何学编程I am seeing more than 3 row are showing on Simulator.
I wrote this code on button click function for backing to second screen (table view screen)
...
MyViewController *History_Back = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
[window addSubview:History_Back.view];
[self.view addSubview:History_Back.view];
....
And in TableView implementation class i am defining it in viewload function which is like below..
-(void)viewDidLoad {
NSLog(@"::::::::::::::");
tableList = [[NSArray alloc]initWithObjects:@"A",@"B",@"C",nil];
[super viewDidLoad];
}
And i want to show only 3 row. Where I should to modify code ?
My tableview coe is here.
-(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] autorelease];
}
cell.textLabel.text=[tableList objectAtIndex:[indexPath row]];
NSLog(@"##############");
return cell;
}
By default, a UITableView
will display as much rows as the tableView height allows (even if the content of the cell is empty). In order not to display more than 3 rows, you have two solutions :
- either you resize your table view height to the appropriate height
- or you can add
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
in the definition of your tableview. This means that you will have to add your own custom separator in theUITableViewCell
design...
精彩评论