Определить UITableViewCell из раскадровки с NIB

Я использовал массив Json для отображения данных с сервера.

когда я изменяю CellIdentifier на @Cell, который я использовал в CellIdentifier, pushDetailView работает, и он переходит на следующую страницу, но когда я снова переключаюсь на CustomCell, просто показываю название города и штата на первой странице, а когда я нажимаю на это, не переходит на следущая страница. причина в том, что мне нужен @CustomCell, потому что мне нужно 2 ярлыка на первой странице, и когда я изменяю его на @cell, он показывает только одну метку.

Спасибо.

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

static NSString *CellIdentifier = @"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

// Configure the cell...

City * cityObject;
cityObject = [ citiesArry objectAtIndex:indexPath.row];
cell.textLabel.text = cityObject.cityState;
cell.detailTextLabel.text = cityObject.cityPopulation;


cell.detailTextLabel.numberOfLines = 4;


//NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://mobileapps.binaryappdev.com/applelogo.png"]  ];

//[[cell imageView] setImage:[UIImage imageWithData:imageData]  ];


return cell;
}


#pragma mark - Navigation

// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


if ([[segue identifier] isEqualToString:@"pushDetailView"])

{

    NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow];
    City * object = [citiesArry objectAtIndex: indexPath.row];

    [[segue destinationViewController] getCity:object];
}
}



#pragma mark -
#pragma mark Class Methods


-(void) retrievedData;

{
NSURL * URL = [ NSURL URLWithString:getDataURL];
NSData * data = [ NSData  dataWithContentsOfURL:URL];

jsonArry = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:Nil];


//city


citiesArry = [[NSMutableArray alloc] init];

//loop

for (int i=0; i<jsonArry.count; i++) {

    NSString * cID = [[ jsonArry objectAtIndex:i] objectForKey:@"id"];
    NSString * cName = [[ jsonArry objectAtIndex:i] objectForKey:@"cityName"];
    NSString * cState = [[ jsonArry objectAtIndex:i] objectForKey:@"cityState"];
    NSString * cCountry = [[ jsonArry objectAtIndex:i] objectForKey:@"country"];
    NSString * cPopulation = [[ jsonArry objectAtIndex:i] objectForKey:@"cityPopulation"];
    NSString * cImage = [[ jsonArry objectAtIndex:i] objectForKey:@"cityImage"];




    [citiesArry addObject:[[City alloc] initWithcityName:cName andcityState:cState andcityCountry:cCountry andcityPopulation:cPopulation andcityImage:cImage andcityID:cID ]];




     }

     [self.tableView reloadData];

}

@end

DetailViewController

@synthesize cityNameLabel, stateLabel, countryLabel, populationLabel, currentCity;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.



[self setLabels];
}

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




#pragma mark -
#pragma mark Class Methods



-(void) getCity:(id)cityObject


{


currentCity = cityObject;

}


-(void) setLabels

{

cityNameLabel.text= currentCity.cityName;
countryLabel.text = currentCity.cityCountry;
stateLabel.text = currentCity.cityState;
populationLabel.text = currentCity.cityPopulation;
cityNameLabel.numberOfLines= 0;

}



@end

1 ответ

Если у вас нет перехода к пользовательской ячейке при добавлении ячейки, будет вызван ваш метод didSelectRow:AtIndexPath. Вы можете сделать сам pushViewController из этого метода или [self executeSegueWithIdentifier: @"pushDetailView" sender: self];

Другие вопросы по тегам