推送表视图,一次选择一行。

时间:2014-03-22 01:40:06

标签: ios objective-c uitableview

我正在尝试在tableview中推送tableview。我的主要目的是每当用户按下一个单元格时,它将进入我想要显示的选定数据。换句话说,只是一个例子,每当我按“2014”我想要显示F型,A8 ....,但不是Sunfire,因为没有2014年“Sunfire ......”每次我按下任何一行RootTableViewController,我总是调用FirstArray。请帮助......

#import "PetsTableViewController.h"
#import "RootViewController.h"
#import <iAd/iAd.h>

@interface PetsTableViewController ()

@end

@implementation PetsTableViewController
@synthesize petsInt; 
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self)    {    }
return self;
}

- (void)viewDidLoad
{

FirstArray = [[NSMutableArray alloc]
            initWithObjects:@"F-Type", @"A8", @"Prius", nil];

SecondArray = [[NSMutableArray alloc]
            initWithObjects:@"S-Type", @"Silverado", @"A8", nil];


ThirdArray = [[NSMutableArray alloc]
            initWithObjects:@"S type", @"Sunfire", nil];

[super viewDidLoad];

}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:         (NSInteger)section
{

if (petsInt == 0)
    return [FirstArray count];
if (petsInt == 1)
    return [SecondArray count];
if (petsInt == 2)
    return [ThirdArray count];
[self.tableView reloadData];
return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"You";


 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier     forIndexPath:indexPath];


if (cell == nil)    {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

if (petsInt == 0)
    cell.textLabel.text = [FirstArray objectAtIndex:indexPath.row];

if (petsInt == 1)
cell.textLabel.text = [SecondArray objectAtIndex:indexPath.row];

if (petsInt == 2)
cell.textLabel.text = [ThirdArray objectAtIndex:indexPath.row];

return cell;
}
@end

0 个答案:

没有答案