したがって、5行あり、選択すると、行番号を含む整数が2番目のView Controllerに渡されます。
各数値にはアイテムを含む独自の配列があり、指定された行のアイテムの量を返す必要があります。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MasterCell";
MasterCell *cell = (MasterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
if (radInt == 0) {
cell.textLabel.text = @"LM";
NSLog(@"My return should have been LM");
}
if (radInt == 1) {
cell.textLabel.text = @"Restauranger";
NSLog(@"My return should have been Rest");
}
if (radInt == 2) {
cell.textLabel.text = [shoppingArray objectAtIndex:indexPath.row];
}
if (radInt == 3) {
cell.textLabel.text = [annatArray objectAtIndex:indexPath.row];
}
//cell.textLabel.text = [listData objectAtIndex:[indexPath row]];
cell.imageView.image = [UIImage imageNamed:@"tab-icon1.png"];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
これはテスト用のコードであり、機能しません。NSLOG は正常に動作しますが、データは単に更新されません...何が間違っていますか? 毎回 LM を Nslogs しますが、選択された行 (radInt) であるログにも 1 があります。
新しいアプローチ
static NSString *CellIdentifier = @"MasterCell";
MasterCell *cell = (MasterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil)
cell = [[MasterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if (radInt == 0) {
cell.textLabel.text = @"LM";
NSLog(@"My return should have been LM");
}
else if (radInt == 1) {
cell.textLabel.text = @"Restauranger";
NSLog(@"My return should have been Rest");
}
else if (radInt == 2) {
cell.textLabel.text = [shoppingArray objectAtIndex:indexPath.row];
}
else if (radInt == 3) {
cell.textLabel.text = [annatArray objectAtIndex:indexPath.row];
}
else {
cell.textLabel.text = @"Noes";
}
//cell.textLabel.text = [listData objectAtIndex:[indexPath row]];
cell.imageView.image = [UIImage imageNamed:@"tab-icon1.png"];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
前の景色----
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *enjoy = [[SecondViewController alloc] init];
if ([[array objectAtIndex:indexPath.row] isEqual:@"Livsmedel"]) {
[enjoy setTitle:[array objectAtIndex:indexPath.row]];
enjoy.radInt = 0;
NSLog(@"0");
}
if ([[array objectAtIndex:indexPath.row] isEqual:@"Restauranger"]) {
[enjoy setTitle:[array objectAtIndex:indexPath.row]];
enjoy.radInt = 1;
NSLog(@"1");
}
if ([[array objectAtIndex:indexPath.row] isEqual:@"Shopping"]) {
[enjoy setTitle:[array objectAtIndex:indexPath.row]];
enjoy.radInt = 2;
}
if ([[array objectAtIndex:indexPath.row] isEqual:@"Annat"]) {
enjoy.radInt = 3;
}
[self performSegueWithIdentifier:@"main" sender:self];
}